How to use Cucumber and Factory Girl together? - cucumber

I'm trying to configure FactoryGirl to work with my Cucumber tests.
I added the following lines in env.rb
require 'factory_girl'
Dir.glob(File.join(File.dirname(__FILE__), '../../spec/factories/*.rb')).each {|f| require f }
When I run 'cucumber features', there's no problem.
I now add a file called teacher.rb to spec/factories and add the following in:
FactoryGirl.define do
factory :teacher do
first_name "John"
last_name "Smith"
end
end
Now when I run cucumber features I get:
uninitialized constant FactoryGirl (NameError)
I'm obviously missing something, but what is it? How do I get Cucumber to work with Factory Girl?
Thanks!

Make sure you have these steps covered. They worked for me flawlessly.
http://collectiveidea.com/blog/archives/2010/09/09/practical-cucumber-factory-girl-steps/
Mainly you have to require "factory_girl/step_definitions"

I'm just going to repeat what Dan Croak said, as it can be incredibly frustrating. (Even the factory_girl_rails plugin points to the wrong file.) You need to follow the syntax here, instead:
https://github.com/thoughtbot/factory_girl/tree/1.3.x
Thanks Dan!!

I had the same problem with cucumber in rails4. Running rake cucumber features instead of just cucumber features solved the problem.

Related

Where does CucumberTestCase belong?

I'm trying to follow Android BDD with Cucumber and Espresso — the full guide but I'm getting the error:
"No tests found."
I can see in the logs that the CucumberTestRunner got invoked successfully. So it seems like Cucumber can't find its own test cases. I think my .feature files are in the right place, so that only leaves CucumberTestCase which could be misplaced. The tutorial puts it in a packaged called com.sniper.bdd.test.
Where does CucumberTestCase belong?
I was able to get Cucumber to find the tests by putting CucumberTestCase in the package <package name from AndroidManifest>.test.
So in the tutorial I guess it should have been in com.sniper.test not com.sniper.bdd.test.

Skip JHipster integration tests using gradle

I am using JHipster 3.4.0 with gradle.
Excuse me for newbie questions.
There are times when I don't trust hot reloads and want to do full clean build.
However, executing 'build' task always lead to running integration tests.
Doing something like
test {
// include '**/*UnitTest*'
// include '**/*IntTest*'
// ignoreFailures true
// reports.html.enabled = false
}
in build.gradle doesn't help.
So how do I skip integration tests for full clean build?
And just to confirm, the task to do full clean build is 'build' right?
Thanks in advance,
Sam
To partially answer my own questions. Just found out the command line
gradle build -x test
will do the trick. But I don't think that answer my question of why comment out test task above doesn't work
The reason why the test are still running, when commenting the includes is, that test task has default values (if you don't overwrite them). So all classes in src/main/test are used as test classes. Your way by passing a command line parameter is the way to go.

Not complete test suite with Spec Explorer 2010

I’m trying out Spec Explorer, and now I have this bug that my test suite is incomplete. I don't get an error or anything, it’s just that I would expect 16 test cases and I only have 11 of them.
The problem I have is with the sample project that is in Spec Explorer 2010. Because I’m new at this I was trying different stuff out with the sample project, so stuff like expanding the range and expanding the double add to quadruple add. This last one was where I noticed that I was missing some test cases. I changed it back to triple add, to watch if the problem was there to. And as I expected I missed a test case again. Only with the triple I expected 8 test cases and I only got 7.
The only thing I changed in the code:
machine DoubleAddScenario() : Main where ForExploration = true
{
(Add(_); Add; Add; ReadAndReset)*
}
I’ve also tried to do this
(Add(_); Add(_); Add(_); ReadAndReset)*
But same problem there. The test case I’m missing is the Add(1); Add(2); Add(1). I’ve also tried calling only this one, and that works, so why am I missing it in my test suite?
Am I doing something wrong, or does Spec Explorer filter something for me? And if it is Spec Explorer where does it make this decision?
good question. The reason why the test case is missing is, that Spec Explorer uses step (transition) coverage and not full path coverage as coverage criterion. So you will find a test case which uses in first step "Add(1)" another one which uses in the second step "Add(2)" and finally a test case which uses "Add(1)" in step 3 but not necessarily one single test case with the exact combination. You find the answers (as really a lot of question were asked there) in the forum and help of Spec Explorer:
http://msdn.microsoft.com/en-us/library/ee620427.aspx
http://social.msdn.microsoft.com/Forums/en-US/977b90c1-8938-474a-840e-14fd78b1af3e/spec-explorer-wmethod?forum=specexplorer
Spec Explorer is used in real world testing so the problem (only one of the many in MBT) with exponential explosion for path coverage had to be worked around. The extremely cool solution of Spec Explorer is the Cord-language (or regular language if you want). Instead of tedious programming test cases Spec Explorer allows us now to only sketch the test case with scenarios. The details and combinations comes out of the generic model. In practice this is what we (at least all the projects I did) really want. And as you see you can add your missing test case if you really need it.

GGTS can't run Groovy Shell

I'm using the Groovy Grails Tool Suite to practice Groovy. I want to run a Groovy Shell, but when I create a new shell and try to run it, I get this error:
Could not find $jarName on the class path. Please add it manually
What does this mean, and how do I resolve this?
I believe this is happening because JLine can't be found on your classpath. I submitted a PR to make the error message in this case actually useful.
I had a similar problem with this exact same message, but the reason was that I was attempting to run the script without specifying which script to run. Ensure you have the script open in the editing window and trying running it again - that got rid of the message for me.

Correct location (in Gradle) to put code that should be run in _all_ test cases?

Just wondering... I have some code (disabling certain logging output) that I'd like to be run before all tests...
I do not see any such examples for JUnit/Groovy testing in the samples directory... is there a good/correct place to put such code?
Thank you!
Misha
p.s. I am using the 0.9 preview 3 version.
According to the Test source code, you should be able to set a beforeSuite/beforeTest Closure on the test Task. I haven't tried it, but I imagine it works something like this:
test {
beforeSuite{
//run custom setup code here
}
}

Resources