我使用导轨spec
(以及capybara
和factory 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...
怎么可能
答案 0 :(得分:1)
这里讨论了这个问题:https://github.com/rails/spring/issues/209,但是在shoulda-matcher的自述文件中,gem说明如何使用preloader安装它,基本上我的解决方案是:
将gemfile中的rspec-rails行移到shoulda-matchers上面
在Gemfile中为shoulda-matchers添加require :: false为
添加要求&#39; shoulda / matchers&#39;在spec_helper.rb
我的Gemfile看起来像:
group :test do
gem "rspec-rails"
gem 'shoulda-matchers', require: false
gem 'machinist'
end
现在我的应用程序与shoulda helper在春天工作正常!