Created
July 2, 2010 08:52
-
-
Save cncolder/461120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/factories.rb | |
class F | |
class << self | |
{:a => :attributes_for, :b => :build, :c => :create, :d => :define, :s => :stub, :* => :sequence, :+ => :next}.each do |k,v| | |
delegate v, :to => Factory | |
alias_method k, v | |
end | |
end | |
end | |
F.d :user do |u| | |
u.name "foo" | |
u.full_name "福娃" | |
u.password "0" | |
end | |
F.* :foos do |n| | |
"foo_#{n}" | |
end | |
# spec/models/user_spec.rb | |
require "spec_helper" | |
describe User do | |
after do | |
User.delete_all | |
end | |
it "should valid" do | |
F.b(:user).should be_valid | |
end | |
it "should save success" do | |
F.c(:user).should_not be_new_record | |
User.all.should be_one | |
end | |
it "should product some foos" do | |
F.+(:foos).should eql "foo_1" | |
(F + :foos).should eql "foo_2" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment