Skip to content

Instantly share code, notes, and snippets.

@cncolder
Created July 2, 2010 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cncolder/461120 to your computer and use it in GitHub Desktop.
Save cncolder/461120 to your computer and use it in GitHub Desktop.
# 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