I'm setting up my Authlogic user session features. And I'm in some kind of co开发者_JAVA百科nfusion. When I run:
cucumber features
I get some red errors
Scenario: User signs in successfully # features/user_sessions.feature:21
Given a user exists with login: "sachin", password: "secret" # features/step_definitions/pickle_steps.rb:4
When I go to the login page # features/step_definitions/webrat_steps.rb:15
And I login as "sachin" with password "secret" # features/step_definitions/user_session_setps.rb:5
Then I should see "Login successful" # features/step_definitions/webrat_steps.rb:123
And I should be logged in # features/user_sessions.feature:26
Ambiguous match of "I should be logged in":
features/step_definitions/pickle_steps.rb:55:in `/^((?:(?:I|myself|me|my)|(?:(?:a|an|another|the|that) )?(?:(?:(?:(?:first|last|(?:\d+(?:st|nd|rd|th))) )?(?:user))|(?:(?:user)(?::? "(?:[^\"]|\.)*"))))) should (?:be|have) (?:an? )?((?:duplicable|readonly|nil|store[_ ]full[_ ]sti[_ ]class|new[_ ]record|equal|present|eql|marked[_ ]for[_ ]destruction|valid[_ ]password|valid[_ ]with[_ ]callbacks|logged[_ ]in|valid[_ ]without[_ ]callbacks|respond[_ ]to[_ ]without[_ ]attributes|valid|logged[_ ]out|respond[_ ]to|instance[_ ]variable[_ ]defined|admin|blank|changed|tainted|unserializable[_ ]attribute|locking[_ ]enabled|has[_ ]role|instance[_ ]of|partial[_ ]updates|kind[_ ]of|attribute[_ ]present|is[_ ]a|frozen|invalid|acts[_ ]like|method[_ ]exists|has[_ ]attribute|disable[_ ]perishable[_ ]token[_ ]maintenance|is[_ ]haml|id|created[_ ]at|updated[_ ]at|login|crypted[_ ]password|password[_ ]salt|persistence[_ ]token|login[_ ]count|last[_ ]request[_ ]at|last[_ ]login[_ ]at|current[_ ]login[_ ]at|last[_ ]login[_ ]ip|current[_ ]login[_ ]ip|roles|first[_ ]name|last[_ ]name|perishable[_ ]token|email))$/'
features/step_definitions/user_session_setps.rb:13:in `/^I should be logged in$/'
You can run again with --guess to make Cucumber be more smart about it
(Cucumber::Ambiguous)
features/user_sessions.feature:26:in `And I should be logged in'
Failing Scenarios:
cucumber features/user_sessions.feature:7 # Scenario: User is not signed up
cucumber features/user_sessions.feature:14 # Scenario: User enters wrong password
cucumber features/user_sessions.feature:21 # Scenario: User signs in successfully
And as cucumber suggests, and when I run with --guess option:
cucumber features --guess
All come green and passes. Is this the expected behavior or error??
AFAIK, if you have 2 different step definitions that are the same, Cucumber does not know which one to run. Using the --guess flag forces Cucumber to pick the most likely one. The cucumber rake tasks use the --strict flag, and will fail if you have ambigious steps.
Essectially, you need to consider the 2 steps (one in pickle steps and one in user_session_steps) that are conflicting and make a decision as to which one to use, then delete the other one.
Consider these step definitions:
Given /Three (.*) mice/ do |disability|
# some code
end
Given /Three blind (.*)/ do |animal|
# some other code..
end
And a plain text step:
Given Three blind mice
Cucumber can’t make a decision about what Step Definition to execute, and will raise a Cucumber::Ambiguous
error telling you to fix the ambiguity.
Guess mode
Running the plain text step will match the Regexp of both step definitions and raise Cucumber::Ambiguous
. However,
if you run Cucumber with --guess
, it will guess that you were aiming for the step definition with 2 match groups.
There is ranking logic that gets invoked when the option is turned on:
- The longest Regexp with 0 capture groups always wins.
- The Regexp with the most capture groups wins (when there are none with 0 groups).
- If there are 2+ Regexen with the same number of capture groups, the one with the shortest overall captured string length wins.
- If there are still 2+ options then an Ambiguous error is raised.
So if you try --guess with the mice above, Cucumber will pick /Three blind (.*)/, because “mice” is shorter than “blind”.
More details here
for $ rake
to work properly, specify cucumber's guess mode
in lib/tasks/cucumber.rake
, specify t.cucumber_opts = "--guess"
:
# ...
namespace :cucumber do
Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t|
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
t.fork = true # You may get faster startup if you set this to false
t.profile = 'default'
t.cucumber_opts = "--guess" # <------- add this line -------<<<
end
# ...
end
# ...
精彩评论