添加弹簧宝石断裂测试 - 导轨

时间:2014-04-09 21:12:17

标签: ruby-on-rails ruby rspec spring-gem

我使用导轨spec(以及capybarafactory girl进行了一些测试并且传递得很好

describe "project creation" do
  before(:each) do
    @project = FactoryGirl.create(:project)
  end
  it "create projects fluently" do
    visit root_path
    @project.should validate_presence_of(:title)
  end
end

然后我安装了spring,当我运行spring rspec spec/features/projects_spec.rb时,它会抛出

Failure/Error: @project.should validate_presence_of(:title)
     NoMethodError:
       undefined method `validate_presence_of' for #<RSpec::Core::ExampleGroup...

怎么可能

1 个答案:

答案 0 :(得分:1)

这里讨论了这个问题:https://github.com/rails/spring/issues/209,但是在shoulda-matcher的自述文件中,gem说明如何使用preloader安装它,基本上我的解决方案是:

  1. 将gemfile中的rspec-rails行移到shoulda-matchers上面

  2. 在Gemfile中为shoulda-matchers添加require :: false为

  3. 添加要求&#39; shoulda / matchers&#39;在spec_helper.rb

  4. 我的Gemfile看起来像:

    group :test do
      gem "rspec-rails"
      gem 'shoulda-matchers', require: false
      gem 'machinist'
    end
    

    现在我的应用程序与shoulda helper在春天工作正常!