Skip to content

Instantly share code, notes, and snippets.

@andriusch
Created November 27, 2009 23:15
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 andriusch/244279 to your computer and use it in GitHub Desktop.
Save andriusch/244279 to your computer and use it in GitHub Desktop.
require 'spec'
require 'blueprints'
require 'activerecord'
require File.dirname(__FILE__) + '/../lib/animal'
ActiveRecord::Base.establish_connection(:database => 'fixtures_test', :adapter => 'mysql', :username => 'root')
#ActiveRecord::Base.connection.create_table :animals do |t|
# t.string :species, :size, :color
#end
Spec::Runner.configure do |config|
config.enable_blueprints :root => File.dirname(__FILE__) + '/..'
end
describe Animal do
before do
build :tiger, :bunny
end
it "should count 2 animals" do
Animal.count.should == 2
end
it "should have 2 animals" do
Animal.all.should have(2).items
end
it "should have correct tiger's species" do
@tiger.species.should == 'Tiger'
end
it "should have correct tiger's size" do
@tiger.size.should == 'big'
end
it "should have correct bunny's species" do
@bunny.species.should == 'Bunny'
end
it "should have correct bunny's size" do
@bunny.size.should == 'small'
end
it "should have correct bunny's color" do
@bunny.color.should == 'white'
end
end
require 'spec'
require 'blueprints'
require 'activerecord'
require File.dirname(__FILE__) + '/../lib/animal'
ActiveRecord::Base.establish_connection(:database => 'fixtures_test', :adapter => 'mysql', :username => 'root')
#ActiveRecord::Base.connection.create_table :animals do |t|
# t.string :species, :size, :color
#end
Spec::Runner.configure do |config|
config.enable_blueprints :root => File.dirname(__FILE__) + '/..', :prebuild => [:tiger, :bunny]
end
describe Animal do
before do
build :tiger, :bunny
end
it "should count 2 animals" do
Animal.count.should == 2
end
it "should have 2 animals" do
Animal.all.should have(2).items
end
it "should have correct tiger's species" do
@tiger.species.should == 'Tiger'
end
it "should have correct tiger's size" do
@tiger.size.should == 'big'
end
it "should have correct bunny's species" do
@bunny.species.should == 'Bunny'
end
it "should have correct bunny's size" do
@bunny.size.should == 'small'
end
it "should have correct bunny's color" do
@bunny.color.should == 'white'
end
end
require 'spec'
require 'blueprints'
require 'activerecord'
require File.dirname(__FILE__) + '/../lib/animal'
ActiveRecord::Base.establish_connection(:database => 'fixtures_test', :adapter => 'mysql', :username => 'root')
#ActiveRecord::Base.connection.create_table :animals do |t|
# t.string :species, :size, :color
#end
Spec::Runner.configure do |config|
config.enable_blueprints :root => File.dirname(__FILE__) + '/..', :prebuild => [:tiger, :bunny]
end
describe Animal do
10.times do |i|
describe "time #{i}" do
before do
build :tiger, :bunny
end
it "should count 2 animals" do
Animal.count.should == 2
end
it "should have 2 animals" do
Animal.all.should have(2).items
end
it "should have correct tiger's species" do
@tiger.species.should == 'Tiger'
end
it "should have correct tiger's size" do
@tiger.size.should == 'big'
end
it "should have correct bunny's species" do
@bunny.species.should == 'Bunny'
end
it "should have correct bunny's size" do
@bunny.size.should == 'small'
end
it "should have correct bunny's color" do
@bunny.color.should == 'white'
end
end
end
end
require 'spec'
require 'factory_girl'
require 'activerecord'
require File.dirname(__FILE__) + '/../lib/animal'
ActiveRecord::Base.establish_connection(:database => 'fixtures_test', :adapter => 'mysql', :username => 'root')
#ActiveRecord::Base.connection.create_table :animals do |t|
# t.string :species, :size, :color
#end
Spec::Runner.configure do |config|
Animal.delete_all
end
describe Animal do
before do
ActiveRecord::Base.connection.increment_open_transactions
ActiveRecord::Base.connection.transaction_joinable = false
ActiveRecord::Base.connection.begin_db_transaction
@bunny = Factory(:animal, :color => 'white')
@tiger = Factory(:animal, :species => 'Tiger', :size => 'big')
end
after do
ActiveRecord::Base.connection.rollback_db_transaction
ActiveRecord::Base.connection.decrement_open_transactions
end
it "should count 2 animals" do
Animal.count.should == 2
end
it "should have 2 animals" do
Animal.all.should have(2).items
end
it "should have correct tiger's species" do
@tiger.species.should == 'Tiger'
end
it "should have correct tiger's size" do
@tiger.size.should == 'big'
end
it "should have correct bunny's species" do
@bunny.species.should == 'Bunny'
end
it "should have correct bunny's size" do
@bunny.size.should == 'small'
end
it "should have correct bunny's color" do
@bunny.color.should == 'white'
end
end
require 'spec'
require 'factory_girl'
require 'activerecord'
require File.dirname(__FILE__) + '/../lib/animal'
ActiveRecord::Base.establish_connection(:database => 'fixtures_test', :adapter => 'mysql', :username => 'root')
#ActiveRecord::Base.connection.create_table :animals do |t|
# t.string :species, :size, :color
#end
Spec::Runner.configure do |config|
Animal.delete_all
end
describe Animal do
before do
@bunny = Factory(:animal, :color => 'white')
@tiger = Factory(:animal, :species => 'Tiger', :size => 'big')
end
after do
Animal.delete_all
end
it "should count 2 animals" do
Animal.count.should == 2
end
it "should have 2 animals" do
Animal.all.should have(2).items
end
it "should have correct tiger's species" do
@tiger.species.should == 'Tiger'
end
it "should have correct tiger's size" do
@tiger.size.should == 'big'
end
it "should have correct bunny's species" do
@bunny.species.should == 'Bunny'
end
it "should have correct bunny's size" do
@bunny.size.should == 'small'
end
it "should have correct bunny's color" do
@bunny.color.should == 'white'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment