Problem Background: "cucumber declarative step definitions using web_steps.rb" Stack Overflow Question
In troubleshooting the problem in question two contradictory error messages are arrived at; with the statement:
When /^(?:|I )uncheck "([^"]*)"$/ do |field|
check(field)
end
added to 'features/step_definitions/movie_steps.rb' execution of 'bundle exec cucumber features/filter_movie_list.feature' results in:
Ambiguous match of "I uncheck "ratings_G"":
features/step_definitions/movie_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
features/step_definitions/web_steps.rb:65:in '/^(?:|I )uncheck "([^"]*)"$/
However, removal of the step does not result in the step definition from 'web_steps.rb' being utilized; rather, a different error message is displayed:
When I uncheck the following ratings: G, PG-13 # features/step_definitions/movie_steps.rb:44
Undefined step: "When I uncheck "ratings_G"" (Cucumber::Undefined)
./features/step_definitions/movie_steps.rb:52:in `block (2 levels) in <top (required)>'
./features/step_definitions/movie_steps.rb:49:in `each'
./features/step_definitions/movie_steps.rb:49:in `/I (un)?check the following ratings: (.*)/'
features/filter_movie_list.feature:30:in `When I uncheck the following ratings: G, PG-13'
How is it possible for Cucumber to complain that a step is redundant when there are two definitions in two places but then later complain that the very same step is not defined when its duplicate is removed? Is it possible the second error message really means something other than what is stated?
PS: The configuration was arrived at by way of a Cucumber installation with training wheels for CS169.x1 # edX...
It seems that you have one definition called When I uncheck "ratings_G" that is somewhat matched with the call When I uncheck the following ratings: G, P-13 that occurs in the error message. Cucumber is complaining that nothing matches the latter one. Does it exist in your code?
The somewhat matching would possibly explain the ambiguity warning you got initially. The definition matches but not what is found inside the string.
Related
I have a view that ajax-loads the same partial a number of times. Each one contains the result of a rather extensive calculation which takes a number of seconds. On my machine, about 3 times out of 20, instead of the partial I get the error message "Unable to autoload constant Answers::Node::Questions::KurzSinglePunch... expected .../app/models/answers/node/questions/kurz_single_punch.rb to define it" (I shortened the text and the path for legibility). The file is obviously there, since in 17 of 20 cases it is found, and the partial displays correctly in these cases.
In case this is relevant, I use Puma in single mode on a six-year-old Mac running OS 11.6.
This is the topmost part of the error message:
LoadError in KurzReportsController#company Unable to autoload constant Answers::Node::Questions::KurzSinglePunch,
expected /Users/marion/Documents/Projekte/myproject/app/models/answers/node/questions/kurz_single_punch.rb to define it
Extracted source (around line #511):
#509 else
#510 require_or_load(expanded, qualified_name)
*511 raise LoadError,
"Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false)
#512 return from_mod.const_get(const_name)
#513 end
#514 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
Extracted source (around line #195):
#193 def const_missing(const_name)
#194 from_mod = anonymous? ? guess_for_anonymous(const_name) : self
*195 Dependencies.load_missing_constant(from_mod, const_name)
#196 end
#197
#198 #
We assume that the name of the module reflects the nesting
Extracted source (around line #285):
#283 constant.const_get(name)
#284 else
*285 candidate = constant.const_get(name)
#286 next candidate if constant.const_defined?(name, false)
#287 next candidate unless Object.const_defined?(name)
#288 Rails.root: /Users/marion/Documents/Projekte/myproject
Application Trace app/exporters/kurz_report_extractor.rb:63:
in `infos_for_question_id' app/exporters/kurz_report_extractor.rb:59:
in `block in build_survey_hash' app/exporters/kurz_report_extractor.rb:59:
in `map' app/exporters/kurz_report_extractor.rb:59:
in `build_survey_hash' app/exporters/kurz_report_extractor.rb:15:
in `initialize' app/controllers/kurz_reports_controller.rb:27:
in `new' app/controllers/kurz_reports_controller.rb:27:
in `block in company' app/controllers/kurz_reports_controller.rb:25:
in `each' app/controllers/kurz_reports_controller.rb:25:in `company'
After that there is a long section with a Framework trace.
How can it be that Rails is sometimes unable to find this file? And how can I fix this?
describe Item do
it 'calculates price according to a special formula' do
item = Item.new('kettle', price: 200)
item.price.should == 212
end
end
Deprecation Warnings:
Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should with
config.expect_with(:rspec) { |c| c.syntax = :should } instead. Called from E:/work/storeapp/spec/item_spec.rb:9:in `block (2 levels) in '.
If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
config.raise_errors_for_deprecations!, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
1 deprecation warning total
Finished in 0.00505 seconds (files took 0.17058 seconds to load)
1 example, 0 failures
How this warning can be avoided?
Write the test in a new style:
expect(item.price).to eq 212
BTW. it seems you might doing sth quite risk/confusing. Once you assign 200 to the attribute, it will be more than confusing to see another value returned by a getter with a same name. Have you considered leaving the original method alone and defining a new one instead (like price_with_vat)?
Cucumber is complaining that I have an ambiguous match for when I tell it to click a link: Ambiguous match, found 4 elements matching link "Spirits" (Capybara::Ambiguous). So I am trying to match the "Spirits" link exactly.
I looked through this: https://github.com/jnicklas/capybara#exactness and found the exact: true option so I changed my code from:
When(/I click on the (.*) link/) do |link_name|
click_link(link_name)
end
to:
When(/I click on the (.*) link/) do |link_name|
click_link(link_name, exact: true)
end
But now it's complaining with wrong number of arguments (2 for 1) (ArgumentError). I'm on Rails 3.2.13, capybara (2.0.3), cucumber (1.2.3). Anyone know why there is an error?
Your Capybara version is not the latest.
exact method added in 2.1.0. https://github.com/jnicklas/capybara/blob/master/History.md
You need to upgrade the gem.
My rspec test suite is slow. It takes about half a decade to run all the tests. While it's running, I see only that tests are failing.
.......................................................................
.......FFFFFFFFFFFFFFF....F..........FFFFFFFFF.........................
................FFFFFFFFFFFFFFF.....................FF.................
..........................FFF..........................................
.............FFFFFFFFFFFFFFFFFFFFFF....................................
................................................................FFFF...
.......FFFFFFFFF..........................
Then, after staring at this for a few years, I finally get a listing of what is wrong.
Failures:
172481) Foobar should barfoo the barbaz while quux is set to narf
Failure/Error: before { click_link "Enable narf" }
ArgumentError:
wrong number of arguments (0 for 1)
# ./app/helpers/foobar_helper.rb:22:in `gobble'
# ./app/controllers/barbaz_controller.rb:18:in `omgwtf'
# (eval):2:in `click_link'
# ./spec/requests/metasyntactic_spec.rb:43:in `block (5 levels) in <top (required)>'
Is there a way to tell rspec it should display the errors directly - while running the test suite?
You can use the fuubar format, see the doc here : https://github.com/jeffkreeftmeijer/fuubar/
For some reason I keep getting a response code of 500 when I run cucumber, even though all the tests pass. The error occurs randomly for different tests, every time I run it. Sometimes all tests pass as well.
I thought it was a memory issue, so I tried restarting my computer, but that didn't do anything.
An example of the error is:
And I follow "link" # features/step_definitions/web_steps.rb:33
Failed. Response code = 500. Response message = Internal Server Error. (ActiveResource::ServerError)
./app/controllers/companies_controller.rb:23:in `show'
./features/step_definitions/web_steps.rb:35
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
features/manage_sites.feature:256:in `And I follow "link"'
It seems related to the tagging feature. I was using the #wip tag, and when I moved it around, it would cause the sporadic 500 errors. Removing all #wip tags makes all the tests pass.
I could be wrong though. I'll need to try and replicate it consistently.
Would anybody be able to help?