简体   繁体   English

显示错误后rspec-rails gem exec

[英]rspec-rails gem exec after dispaly error

I have create a static_pages_controller.rb 我创建了一个static_pages_controller.rb

which i have create one function 我已经创建了一个功能

def home


end

after that i have create a view home.html.erb which i have just write done this "Sample App" 之后,我创建了一个视图home.html.erb,我刚刚编写完成了此“示例应用程序”

After that i have install gem rspec-rails and create static_pages_spec.rb 之后,我安装了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

i have run this command on terminal 我已经在终端上运行了此命令

$  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

what it is wrong ? 有什么问题吗? with this please hellp me 以此来请我

visit is part of the Capybara DSL. visit是Capybara DSL的一部分。 Whilst it used to be loaded automatically for tests in spec/requests , that was changed in this commit to load automatically for tests in spec/features instead. 虽然它过去通常会自动加载以用于spec/requests测试,但在此提交中已更改为改为自动加载以用于spec/features测试。

You can either move your spec to spec/features and it should work, or you have to explicitly include Capybara::DSL in your spec_helper.rb if you want to leave the spec where it is. 您可以将规范移至spec/features ,它应该可以工作,或者如果您想保留规范,则必须在spec_helper.rb明确包含spec_helper.rb Capybara::DSL

This is assuming you have Capybara installed and required. 这是假设您已安装并需要Capybara。

In you Gemfile you should have: 在您的Gemfile您应该具有:

gem 'capybara'

And in your spec_helper.rb you should have: 并且在您的spec_helper.rb您应该具有:

require 'capybara/rspec'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM