ruby-on-rails-3 – 带有rspec2 beta 5和rails3 beta2的shoulda
发布时间:2020-12-17 02:58:30 所属栏目:百科 来源:网络整理
导读:我已经设置了Rspec2 beta5,并且如下所示在rspec模型测试中使用了shoulda宏. ================= 更新2011年2月18日 现在我们可以使用开箱即用的应用匹配器. 只需在Gemfile中添加gem shoulda-matchers,在spec_helper或任何hack中添加其他内容.它只是运行. ====
|
我已经设置了Rspec2 beta5,并且如下所示在rspec模型测试中使用了shoulda宏.
================= 更新2011年2月18日 现在我们可以使用开箱即用的应用匹配器. 只需在Gemfile中添加gem shoulda-matchers,在spec_helper或任何hack中添加其他内容.它只是运行. ================= 的Gemfile group :test do gem "rspec",">= 2.0.0.beta.4" gem "rspec-rails",">= 2.0.0.beta.4" gem 'shoulda',:git => 'git://github.com/bmaddy/ shoulda.git' gem "faker" gem "machinist" gem "pickle",:git => 'git://github.com/codegram/ pickle.git' gem 'capybara',:git => 'git://github.com/jnicklas/ capybara.git' gem 'database_cleaner',:git => 'git://github.com/bmabey/ database_cleaner.git' gem 'cucumber-rails',:git => 'git://github.com/aslakhellesoy/ cucumber-rails.git' end spec_helper.rb Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
require 'shoulda'
Rspec.configure do |config|
规格/型号/ outlet_spec.rb require 'spec_helper'
describe Outlet do
it { should validate_presence_of(:name) }
end
当我运行规范时,我收到以下错误. [~/rails_apps/rails3_apps/automation (master)?] ? spec spec/models/
outlet_spec.rb
DEPRECATION WARNING: RAILS_ROOT is deprecated! Use Rails.root instead.
(called from join at /home/millisami/.rvm/gems/ruby-1.9.1-p378%rails3/
bundler/gems/shoulda-87e75311f83548760114cd4188afa4f83fecdc22-master/
lib/shoulda/autoload_macros.rb:40)
F
1) Outlet
Failure/Error: it { should validate_presence_of(:name) }
undefined method `validate_presence_of' for
#<Rspec::Core::ExampleGroup::Nested_1:0xc4dc138 @__memoized={}>
# ./spec/models/outlet_spec.rb:4:in `block (2 levels) in <top
(required)>'
Finished in 0.0399 seconds
1 example,1 failures
[~/rails_apps/rails3_apps/automation (master)?] ?
为什么“未定义的方法”?是否会加载? 解决方法
使用RSpec 2.0.0.beta.19
# Gemfile
group :test do
gem "rspec",">= 2.0.0.beta.19"
gem "rspec-rails",">= 2.0.0.beta.17"
gem "shoulda"
end
# spec/spec_helper.rb
require 'rspec/rails'
require 'shoulda/integrations/rspec2' # Add this line
# In your specs....
it { should validate_presence_of(:name) }
运行rake规范现在应该加载并运行包括RSpec 2匹配器在内的规范. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
