首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示错误后rspec-rails gem exec

显示错误后rspec-rails gem exec
EN

Stack Overflow用户
提问于 2014-04-18 16:47:50
回答 1查看 43关注 0票数 1

我已经创建了一个static_pages_controller.rb

我已经创建了一个函数

代码语言:javascript
复制
def home


end

之后,我已经创建了一个视图home.html.erb,我刚刚写了这个“示例应用程序”

之后,我安装了gem rspec-rails并创建了static_pages_spec.rb

代码语言:javascript
复制
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

我已经在终端上运行了这个命令

代码语言:javascript
复制
$  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

这是怎么回事?有了这个请帮助我

EN

回答 1

Stack Overflow用户

发布于 2014-04-18 18:35:35

visit是Capybara DSL的一部分。虽然它过去是为spec/requests中的测试自动加载的,但它被更改为在spec/features中为测试自动加载。

您可以将您的规范移动到spec/features,它应该可以工作,或者如果您想将规范保留在原来的位置,则必须在spec_helper.rb中显式地包含Capybara::DSL

这是假设您已经安装了Capybara并且是必需的。

在你的Gemfile中,你应该有:

代码语言:javascript
复制
gem 'capybara'

在你的spec_helper.rb中,你应该有:

代码语言:javascript
复制
require 'capybara/rspec'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23150663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档