我已经参考了链接http://railscasts.com/episodes/155-beginning-with-cucumber进行测试。
当我before_filter :authenticate_user!
在我的控制器中使用时,我的所有案例都失败了,当我评论before_filter
我的所有测试案例都通过了。我收到以下错误。
Scenario: Create Valid Article
Given I have no articles
And I am on the list of articles
When I follow "New Article"
Unable to find link "New Article" (Capybara::ElementNotFound)
./features/step_definitions/article_steps.rb:25:in `/^I follow "([^\"]*)"$/'
features/manage_articles.feature:15:in `When I follow "New Article"'
And I fill in "article[title]" with "Spuds"
And I fill in "Content" with "Delicious potato wedges!"
And I press "Create"
Then I should see "New article created."
And I should see "Spuds"
And I should see "Delicious potato wedges!"
And I should have 1 article
Failing Scenarios:
cucumber features/manage_articles.feature:12 # Scenario: Create Valid Article
2 scenarios (1 failed, 1 passed)
14 steps (1 failed, 7 skipped, 6 passed)
article_steps.rb
Given /^I have articles titled (.+)$/ do |titles|
titles.split(', ').each do |title|
Article.create!(:title => title)
end
end
When /^I go to the list of articles$/ do
visit articles_path
end
Then /^I should see "(.*?)"$/ do |arg1|
end
Given /^I have no articles$/ do
Article.delete_all
end
Given /^I am on the list of articles$/ do
visit articles_path
end
When /^I follow "([^\"]*)"$/ do |link|
click_link(link)
end
When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
When /^I press "([^\"]*)"$/ do |button|
click_button(button)
end
Then /^I should have ([0-9]+) articles?$/ do |count|
Article.count.should == count.to_i
end