未定义的方法“has_selector?” for nil:NilClass (NoMethodError) 黄瓜 (水豚) 步骤

发布于 2024-10-16 00:02:49 字数 2073 浏览 3 评论 0原文

对于以下问题,我希望得到一些帮助。

当我运行我的黄瓜(使用水豚)功能时,

rake cucumber:wip

出现以下错误:(即由于某种原因未定义响应对象)

  Then I should be able to see 1 announcement # features/step_definitions/view_announcements_steps.rb:8
      undefined method `has_selector?' for nil:NilClass (NoMethodError)
      ./features/step_definitions/view_announcements_steps.rb:10:in `/^I should be able to see (\d+) announcement$/'
      features/view_announcements.feature:13:in `Then I should be able to see 1 announcement'

我有以下黄瓜功能文件:

@wip
    Feature: User views announcements
    As a user
    I want to be able to view announcements
    So that I am up-to-date with the latest news

Background:
    Given there is 1 announcement

Scenario: I am not logged in
    Given I am not logged in
    When I go to main
    Then I should be able to see 1 announcement 

Scenario: I am logged in 
    Given I am logged in as "test/password"
    When I go to main
    Then I should be able to see 1 announcement 

和步骤定义:

Given /^there is|are (\d+) announcement$/ do |arg1|
    arg1.to_i.times do
        Announcement.create!({:title => "Test Announcement",
                                                        :body => "This is a test"})
    end
end

Then /^I should be able to see (\d+) announcement$/ do |arg1|
    response.should have_selector("div#announcement", :count => arg1)
end  

When /^(?:|I )go to (.+)$/ do |page_name|
  visit path_to(page_name)
end

Given /^I am not logged in$/ do
  visit('/users/sign_out') 
end

Given /^user "([^\/]*)\/([^\"]*)" exists$/ do |username, password|
  User.new(:username => username,
           :password => password,
           :password_confirmation => password).save!
end

Given /^I am logged in as "([^\/]*)([^\"]*)"$/ do |username, password| 
  Given %{user "#{username}/#{password}" exists}
  visit('/users/sign_in')#And %{I go to sign_in}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

I would appreciate some help with the following problem.

When I run my cucumber (using capybara) feature using

rake cucumber:wip

I get the following error: (ie the response object is not defined for some reason)

  Then I should be able to see 1 announcement # features/step_definitions/view_announcements_steps.rb:8
      undefined method `has_selector?' for nil:NilClass (NoMethodError)
      ./features/step_definitions/view_announcements_steps.rb:10:in `/^I should be able to see (\d+) announcement$/'
      features/view_announcements.feature:13:in `Then I should be able to see 1 announcement'

I have the following cucumber feature file:

@wip
    Feature: User views announcements
    As a user
    I want to be able to view announcements
    So that I am up-to-date with the latest news

Background:
    Given there is 1 announcement

Scenario: I am not logged in
    Given I am not logged in
    When I go to main
    Then I should be able to see 1 announcement 

Scenario: I am logged in 
    Given I am logged in as "test/password"
    When I go to main
    Then I should be able to see 1 announcement 

and step definitions:

Given /^there is|are (\d+) announcement$/ do |arg1|
    arg1.to_i.times do
        Announcement.create!({:title => "Test Announcement",
                                                        :body => "This is a test"})
    end
end

Then /^I should be able to see (\d+) announcement$/ do |arg1|
    response.should have_selector("div#announcement", :count => arg1)
end  

When /^(?:|I )go to (.+)$/ do |page_name|
  visit path_to(page_name)
end

Given /^I am not logged in$/ do
  visit('/users/sign_out') 
end

Given /^user "([^\/]*)\/([^\"]*)" exists$/ do |username, password|
  User.new(:username => username,
           :password => password,
           :password_confirmation => password).save!
end

Given /^I am logged in as "([^\/]*)([^\"]*)"$/ do |username, password| 
  Given %{user "#{username}/#{password}" exists}
  visit('/users/sign_in')#And %{I go to sign_in}
  And %{I fill in "user_password" with "#{password}"}
  And %{I press "Sign in"}
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2024-10-23 00:02:49

事实证明,features/support/paths.rb 中的路径不正确。

It turns out that a path was incorrect in features/support/paths.rb.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文