Skip to content

Instantly share code, notes, and snippets.

@mlins
Created July 25, 2008 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mlins/2372 to your computer and use it in GitHub Desktop.
Save mlins/2372 to your computer and use it in GitHub Desktop.
class Migration
class << self
attr_accessor :model
def set_model(model)
@model = eval(model)
end
end
def run
self.class.model.count
records = self.class.model.find
end
end
require 'spec_helper.rb'
describe "Migration" do
before do
@record = mock('record', {:name => 'Pete'})
MyModel = mock('MyModel Class', {:count => 1, :find => [@record]})
require 'my_migration'
@migration = MyMigration.new
end
it "should get a count of the records" do
MyModel.should_receive(:count)
@migration.run
end
it "should find the records" do
MyModel.should_receive(:find)
@migration.run
end
after do
Object.send(:remove_const, :MyModel)
end
end
require 'migration'
class MyMigration < Migration
set_model 'MyModel'
end
begin
require 'spec'
rescue LoadError
require 'rubygems'
gem 'rspec'
require 'spec'
end
# Spec::Runner.configure do |config|
# config.mock_with :flexmock
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment