看了这么多案例,貌似比较推荐是 Rspec+factory-girl
我尝试了一下照着 ruby-china 的代码弄了下
# coding: utf-8
require 'spec_helper'
describe Location do
before(:each) do
@location = Factory(:location,:name => 'foo')
end
it "should validates_uniqueness_of :name ignore case" do
Location.create(:name => "FoO").should have(1).error_on(:name)
end
end
但是他说找不到 Factory,那我应该在那配置这个 factory-girl 呢 错误信息
Failures:
1) Location should validates_uniqueness_of :name ignore case
Failure/Error: @location = Factory(:location,:name => 'foo')
NoMethodError:
undefined method `Factory' for #<RSpec::Core::ExampleGroup::Nested_1:0x007ffdfeb93ad0>
# ./spec/models/location_spec.rb:6:in `block (2 levels) in <top (required)>'