Capybara NoMethodError

时间:2014-07-05 16:51:00

标签: ruby-on-rails rspec capybara

我目前正在阅读Michael Hartl的Rails书籍,并且在第3章开始编写测试。我的问题是,我无法进行第一次测试。从谷歌搜索和阅读几个线程没有stackoverflow,以及Capybara自述文件,我已经从他的代码做了一些更改,但我仍然无法使访问功能工作。相关文件包含在下面。

规格/ spec_helper.rb

require 'capybara'
require 'capybara/rspec'

Rspec.configure do |config|
    config.include Capybara::DSL
end

Capybara.configure do |config|
    config.app = "Sample App"
end

功能/ static_pages_spec.rb

require 'spec_helper'

feature "Static pages" do

    feature "Home page" do

        it "should have the content 'Sample App'" do

            visit '/static_pages/home'
            expect(page).to have_content('Sample App')

        end
    end
end

相关的错误消息让我陷入了循环:

Failure/Error: visit '/static_pages/home'
NoMethodError:
    undefined method `call' for "Sample App":String
#./spec/features/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'  

看到错误我尝试从 spec_helper.rb 中删除config.app,但这只会导致另一个错误。

Failure/Error: visit '/static_pages/home'
ArgumentError:
    rack-test requires a rack applicaiton, but none was given
#./spec/features/static_pages_spec.rb:9:in `block (3 levels) in <top (required)>'

1 个答案:

答案 0 :(得分:0)

不确定是什么原因,但在进行了更多研究以解决 spec / features / static_pages_spec.rb 中的此问题后,我需要将require 'spec_helper'更改为require 'rails_helper'