2014-04-18 63 views
1

我已创建一个static_pages_controller.rbRSpec的护栏宝石EXEC

这是我之后,创建一个功能

def home 


end 

我已创建一个视图home.html.erb 我刚才写这样做“示例应用程序”

之后,我有安装宝石RSpec的护栏,并创建static_pages_spec.rb

require 'spec_helper' 
describe "StaticPages" do 
    describe "Home page" do 
     it "should have the content 'Sample App'" do 
      visit '/static_pages/home' 
      page.should have content('Sample App') 
     end 
    end 
end 

我已经运行在终端

$ bundle exec rspec spec/requests/static_pages_spec.rb 
F 

Failures: 

    1) StaticPages Home page should have the content 'Sample App' 
    Failure/Error: visit '/static_pages/home' 
    NoMethodError: 
     undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xa3a7870> 
    # ./spec/requests/static_pages_spec.rb:5:in `block (3 levels) in <top (required)>' 

Finished in 0.00248 seconds 
1 example, 1 failure 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:4 # StaticPages Home page should have the content 'Sample App' 

Randomized with seed 57243 

这个命令什么是错的?与此请请hellp我

回答

1

visit是Capybara DSL的一部分。虽然它曾经在spec/requests中自动加载测试,但in this commit更改为spec/features而自动加载测试。

您可以将您的规格来spec/features,它应该工作,或者你必须明确地包括Capybara::DSLspec_helper.rb,如果你想离开该规范在哪里。

这是假设您已安装并需要安装Capybara。

在你Gemfile你应该有:

gem 'capybara' 

而在你spec_helper.rb你应该有:

require 'capybara/rspec' 
+0

不明白这一点:( – Harman

+0

重命名'规格/请求/ static_pages_spec.rb'是'spec/features/static_pages_spec.rb'(即把它放在features子目录中而不是请求),它应该可以工作。 –

+0

现在我的目录stu就像这样“spec/features/static_pages_spec.rb”,我运行这个命令“ $ bundle exec rspec spec/feat ures/static_pages_spec.rb“无法正常工作 – Harman