我已经创建了一个static_pages_controller.rb
我已经创建了一个函数
def home
end之后,我已经创建了一个视图home.html.erb,我刚刚写了这个“示例应用程序”
之后,我安装了gem rspec-rails并创建了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这是怎么回事?有了这个请帮助我
发布于 2014-04-18 18:35:35
visit是Capybara DSL的一部分。虽然它过去是为spec/requests中的测试自动加载的,但它被更改为在spec/features中为测试自动加载。
您可以将您的规范移动到spec/features,它应该可以工作,或者如果您想将规范保留在原来的位置,则必须在spec_helper.rb中显式地包含Capybara::DSL。
这是假设您已经安装了Capybara并且是必需的。
在你的Gemfile中,你应该有:
gem 'capybara'在你的spec_helper.rb中,你应该有:
require 'capybara/rspec'https://stackoverflow.com/questions/23150663
复制相似问题