Cucumber not finding step definitions - ruby-on-rails

My Cucumber just won't find the step definitions. The file structure (Only the specs folder inside the Rails root) looks like this:
-> specs
-> features
-> main_structure.feature
-> step_definitions
-> main_structure_steps.rb
This is the main_structure.feature:
Feature: Main structure
Scenario: Viewing the Structure page
When I am on the structure page
And this the main_structure_steps.rb:
When(/^I am on the structure page$/) do
visit '/'
end
Now I run the cucumber command like this:
→ cucumber spec/features -r features
I get this output:
Using the default profile...
Feature: Main structure
Scenario: Viewing the Structure page # spec/features/main_structure.feature:2
When I am on the structure page # spec/features/main_structure.feature:3
Undefined step: "I am on the structure page" (Cucumber::Undefined)
spec/features/main_structure.feature:3:in `When I am on the structure page'
1 scenario (1 undefined)
1 step (1 undefined)
0m0.229s
You can implement step definitions for undefined steps with these snippets:
When(/^I am on the structure page$/) do
pending # express the regexp above with the code you wish you had
end
/Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: -r (OptionParser::InvalidOption)
from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `new'
from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:1016:in `process_args'
from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:1066:in `_run'
from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:1059:in `run'
from /Users/rudolf/.rvm/gems/ruby-2.0.0-p247#global/gems/minitest-4.7.5/lib/minitest/unit.rb:795:in `block in autorun'
There is also an error message at the bottom, that doesn't appear when I run the test in RubyMine. But in both cases, the step definitions are not found. This is the Rubymine output:
Testing started at 21:29 ...
You can implement step definitions for undefined steps with these snippets:
When(/^I am on the structure page$/) do
pending # express the regexp above with the code you wish you had
end
1 scenario (1 undefined)
1 step (1 undefined)
0m0.001s
Process finished with exit code 0
Tell me if you need any additional infos.

Try
cucumber spec/features/main_structure.feature -r spec/features

Similar to my question:Cucumber Test acting in a strange way
You can implement step definitions for undefined steps with these snippets:
When(/^I am on the structure page$/) do
pending # express the regexp above with the code you wish you had
end
As the error saying. Put the code above in web_steps.rb and then replace pending # express the regexp above with the code you wish you had with the code you want

I Also had a similar problem with Java and for me the reason was that I had 2 Cucumber plugins installed in NetBeans IDE. I left Cetriolo and removed Cucumber Features and tests started working

make sure glue syntax is like below:
glue={"packageName"}
Here packageName is the package where you step definition java file exists

Related

Agile Web Development Rails 5 test failures

I just finished creating the Depot app from the Agile Web Development with Rails 5 textbook. For some reason, I am getting errors & failures when I run 'rails test'. Can someone explain why this is happening?
My Github repository is here: https://github.com/christopheragnus/Agile_Web_Development_with_Rails_5
Christophers-MacBook-Pro-3:depot Agnus$ rails test
Running via Spring preloader in process 45997
Run options: --seed 52040
# Running:
..............F
Failure:
LineItemsControllerTest#test_should_create_line_item [/Users/Agnus/Dropbox/CA/AgileWebDevelopment/depot/test/controllers/line_items_controller_test.rb:25]:
<Your Cart> expected but was
<>..
Expected 0 to be >= 1.
bin/rails test test/controllers/line_items_controller_test.rb:18
..E
Error:
OrderMailerTest#test_shipped:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b60cc410>
Did you mean? login_as
test/test_helper.rb:12:in `login_as'
test/test_helper.rb:20:in `setup'
bin/rails test test/mailers/order_mailer_test.rb:12
E
Error:
OrderMailerTest#test_received:
NameError: undefined local variable or method `login_url' for #<OrderMailerTest:0x007ff7b6058880>
Did you mean? login_as
test/test_helper.rb:12:in `login_as'
test/test_helper.rb:20:in `setup'
bin/rails test test/mailers/order_mailer_test.rb:4
E
Error:
AdminControllerTest#test_should_get_index:
NameError: undefined local variable or method `admin_index_url' for #<AdminControllerTest:0x007ff7b4ca8880>
test/controllers/admin_controller_test.rb:5:in `block in <class:AdminControllerTest>'
bin/rails test test/controllers/admin_controller_test.rb:4
...........................
Finished in 5.740751s, 8.1871 runs/s, 14.4580 assertions/s.
47 runs, 83 assertions, 1 failures, 3 errors, 0 skips
The undefined errors mean just that: you are calling "login_url" but rails cannot find it anywhere. If you simply copy pasted code from the book you should go to the section where they create this helper file and see where they defined the login_url.
The test failure, opposed to the error, is that it is expecting an h2 element to exist with the name "Your Cart" but it cannot find it. To debug this, you could either go through the code and make sure all the routing/rerouting is correct and that the views are correctly structured and there's no typos- or run the app and go through what the test is doing and see if the results you are seeing is what is expected. Then- we can go from there.
As a rule of thumb, it is good to get into the habit of googling errors which can help give you an idea of where to troubleshoot the issues in your project.

Disable rest-client output on minitest

I've searched for this, but without success.
I have some tests (minitest) that use RestClient and Webmock. When passing for those tests I always have the request logged, polluting the test ouput:
[$] rake
Run options: --seed 60435
Running:
.........................................................RestClient.get "http://example.com/some_controller/some_action?userLocale=fr_FR", "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "User-Agent"=>"rest-client/2.0.0 (darwin14.1.0 x86_64) ruby/2.2.1p85" # => 200 OK | 4 bytes
Is there a way to disable this ?
[EDIT]
Just to add, if I call the same address using ruby URL I have nothing logged (even using webmock) so it really is something related with Rest-client.
I already tried to set the ENV['RESTCLIENT_LOG'] variable, but without success.
What about:
RestClient.stub :log, '' do
# Your test code here
end
http://www.rubydoc.info/gems/minitest/4.2.0/Object:stub
You have many other options to redirect the log output:
In your test_helper.rb:
RestClient.log = 'tmp/test.log'
http://www.rubydoc.info/gems/rest-client/1.8.0/RestClient.log=
From the command line:
RESTCLIENT_LOG=tmp/restclient.log bundle exec rails test
In last resort you could monkey patch:
# test_helper.rb
RestClient.class_eval do
def self.log
''
end
end

Ruby on Rails rspec runs tests succesfully, but Guard + Spork doesn't find methods for Devise

I tried to add a few tests to my Ruby on Rails -application. When I run them on command line using command rspec, it runs fine:
Finished in 0.87603 seconds 3 examples, 0 failures
When starting guard, it runs them fine for the first time as well. It gives this kind of message even though I'm not using minitest:
/.rvm/gems/ruby-2.0.0-p353/gems/minitest-4.7.5/lib/minitest/unit.rb:1037:in `block in process_args': invalid option: --drb (OptionParser::InvalidOption)
I haven't configured to use MiniTest, so I guess there might be something wrong with my configuration files?
However, when I make changes to my user_pages_spec.rb and save, which triggers Guard to run the tests, it gives this kind of error:
Running tests with args ["--drb", "-f", "progress", "-r", "/home/.rvm/gems/ruby-2.0.0-p353/gems/guard-rspec-2.5.0/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec/requests/user_pages_spec.rb"]...
Failures:
1)
User pages signup page
Failure/Error: before { visit new_user_registration_path }
ActionView::Template::Error:
undefined method `devise_error_messages!' for #<#<Class:0x00000006b18248>:0x00000006b226f8>
2)
User pages signup page
Failure/Error: before { visit new_user_registration_path }
ActionView::Template::Error:
undefined method `devise_error_messages!' for #<#<Class:0x00000006b18248>:0x000000066de560>
Basicly not finding those methods running the same tests the second time. Tests I run for another page which contains only static content works fine.
Here are some files:
Gemfile: http://pastebin.com/bHgxXYZ3
Guardfile: http://pastebin.com/Rnhz2tsJ
spec_helper: http://pastebin.com/Jpvu3k2Q
.rspec: http://pastebin.com/B0bzmE0n
If something's missing, just give me a note. Thanks for helping :)
Do you also have these errors when starting spork and then running your specs (without Guard)?
For the MiniTest error message, be sure that you don't have a test/ folder in your project.

Integrate Specs2 results with Jenkins

I want to integrate the Specs2 test results with Jenkins.
I was added the below properties in sbt:
resolver:
"maven specs2" at "http://mvnrepository.com/artifact"
libraryDependencies:
"org.specs2" %% "specs2" % "2.0-RC1" % "test",
System Property:
testOptions in Test += Tests.Setup(() => System.setProperty("specs2.outDir", "/target/specs2-reports")) //Option1
//testOptions in Test += Tests.Setup(() => System.setProperty("specs2.junit.outDir", "/target/specs2-reports")) //Option2
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "console", "junitxml")
If I run the below command, it is not generating any specs reports in the above mentioned directory("/target/specs2-reports").
sbt> test
If I run the below command, it is asking for the directory as shown in the below error message:
sbt> test-only -- junitxml
[error] Could not run test code.model.UserSpec: java.lang.IllegalArgumentException: junitxml requires directory to be specified, example: junitxml(directory="xxx")
And it is working only if I give the directory as shown below:
sbt> test-only -- junitxml(directory="\target\specs-reports")
But sometimes its not generating all the specs report xmls (some times generating only one report, sometimes only two reports etc.).
If I give test-only -- junitxml(directory="\target\specs-reports") in the jenkins it is giving the below error.
[error] Not a valid key: junitxml (similar: ivy-xml)
[error] junitxml(
[error] ^
My main goal is, I want to generate the consolidated test reports in junit xml format and integrate with Jenkins. Kindly help me to solve my problem.
Best Regards,
Hari
The option for the junitxml output directory is: "specs2.junit.outDir" and the default value is "target/test-reports".
So if you don't change anything you could just instruct Jenkins to grab the xml files from "target/test-reports" which is what I usually do.
Also you might have to enclose your sbt commands in Jenkins with quotes. This is what I typically do:
"test-only -- html junitxml console"

Rspec test fails on Jenkins when open file from /tmp folder

I have such trouble with Jenkins.
I'm trying to test PDF generation using RSpec.
RSpec test failing, when trying to open receuntly generated PDF file. (File is saving into /tmp directory)
//TEST
pdf_generator = PdfGenerator::InvoicePdf.new(invoice)
pdf_file_path = pdf_generator.to_pdf
and I get error(in Jenkins only):
Failures:
1) OrdersController GET show while authorized as customer INVOICE .generate_pdf pdf contains correct text
Failure/Error: pdf_file_path = pdf_generator.to_pdf
Errno::ENOENT:
No such file or directory - /var/lib/jenkins/jobs/TicketCo for Gerrit/workspace/tmp/1371464314.pdf
# ./lib/pdf_generator/invoice_pdf.rb:80:in `to_pdf'
# ./spec/controllers/orders_controller_spec.rb:413:in `block (5 levels) in <top (required)>'
and here is the line in method, which causes error:
def to_pdf
Prawn::Document.generate(temp_pdf_file_path)
....
end
Can someone help me with this trouble ?
Maybe I need to change PDF path for Jenkins ?
I got an answer. If you have such problem just create /tmp folder in Jenkins workspace. In configurate tab you can add this command
mkdir -p tmp

Resources