为什么我的规范/支持文件没有被 rspec 接收? [英] Why aren't my spec/support files being picked up with rspec?

查看:43
本文介绍了为什么我的规范/支持文件没有被 rspec 接收?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误,我的 spec/support 文件夹中有一个utilities.rb 文件来保存一些帮助函数,例如登录方法.

I have a weird error, I've got a utilities.rb file in my spec/support folder to hold some helper functions such as sign in method.

spec/support/utilities.rb

spec/support/utilities.rb

include ApplicationHelper


def sign_in(user)
  visit new_user_session_path
  fill_in "Email",    with: user.email
  fill_in "Password", with: user.password
  click_button "Sign in"
end

我的守卫档案:

require 'active_support/core_ext'


guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch('config/environments/test.rb')
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb') { :rspec }
  watch('test/test_helper.rb') { :test_unit }
  watch('spec/support/')
  watch(%r{^spec/support/.+\.rb$})
  watch(%r{features/support/}) { :cucumber }
end

guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }

  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")
  end

end

在我的集成测试请求/link_pages_spec.rb 中,我尝试做这样的事情,但它给了我一个错误

And in my integration test requests/link_pages_spec.rb I try to do something like this but it gives me an error

require 'spec_helper'

describe "Link pages" do

  subject { page }

  describe 'creating a link' do

    before do
      sign_in FactoryGirl.create(:user)
      visit new_link_path
    end

    describe "with invalid information" do
      it "should not create a link" do
        expect { click_button 'Create Link' }.not_to change(Link, :count)
      end
    end

  end

end

错误:

Failure/Error: sign_in FactoryGirl.create(:user)
     NoMethodError:
       undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007f8ebb563e10>
     # ./spec/support/utilities.rb:5:in `sign_in'
     # ./spec/requests/link_pages_spec.rb:10:in `block (3 levels) in <top (required)>'

奇怪的是,如果我删除链接页面规范中的描述块,就没有错误..

Weird thing is, if I remove the describe block in my link pages spec, there is no error..

推荐答案

找到了解决方案,错误是由最新的 Capybara gem 引起的.Capybara 2+ 要求您在规范/功能中进行集成测试.我只是回滚到旧版本.

Worked out the solution, the error was being caused due to the latest Capybara gem. Capybara 2+ requires that you have your integration tests in spec/features. I simply just rolled back to an older version.

参见 http://alindeman.github.com/2012/11/11/rspec-rails-and-capybara-2.0-what-you-need-to-know.html

这篇关于为什么我的规范/支持文件没有被 rspec 接收?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆