test/lib/seedbank/runner_test.rb in seedbank-0.3.0 vs test/lib/seedbank/runner_test.rb in seedbank-0.4.0.pre

- old
+ new

@@ -1,66 +1,160 @@ require 'test_helper' describe Seedbank::Runner do - before do - flexmock(FakeModel) - end - describe "seeds with dependency" do subject { Rake::Task['db:seed:dependent'] } it "runs the dependencies in order" do - FakeModel.should_receive(:seed).with('dependency').once.ordered - FakeModel.should_receive(:seed).with('dependent').once.ordered + FakeModel.expect :seed, true, ['dependency'] + FakeModel.expect :seed, true, ['dependent'] subject.invoke + + FakeModel.verify end + + it "executes the body of the dependencies exactly once per invocation" do + FakeModel.expect :seed, true, ['dependency'] + FakeModel.expect :seed, true, ['dependent'] + FakeModel.expect :seed, true, ['dependency'] + FakeModel.expect :seed, true, ['dependent'] + + subject.invoke + + # Allow all tasks to be re-executed, including dependencies + Rake.application.tasks.each { |t| t.reenable } + + subject.invoke + + FakeModel.verify + end end describe "seeds with multiple dependencies" do subject { Rake::Task['db:seed:dependent_on_several'] } it "runs the dependencies in order" do - FakeModel.should_receive(:seed).with('dependency').once.ordered - FakeModel.should_receive(:seed).with('dependency2').once.ordered - FakeModel.should_receive(:seed).with('dependent on several').once.ordered + FakeModel.expect :seed, true, ['dependency'] + FakeModel.expect :seed, true, ['dependency2'] + FakeModel.expect :seed, true, ['dependent on several'] subject.invoke + + FakeModel.verify end end describe "seeds with nested dependencies" do subject { Rake::Task['db:seed:dependent_on_nested'] } it "runs all dependencies in order" do - FakeModel.should_receive(:seed).with('dependency').once.ordered - FakeModel.should_receive(:seed).with('dependent').once.ordered - FakeModel.should_receive(:seed).with('dependency2').once.ordered - FakeModel.should_receive(:seed).with('dependent on nested').once.ordered + FakeModel.expect :seed, true, ['dependency'] + FakeModel.expect :seed, true, ['dependent'] + FakeModel.expect :seed, true, ['dependency2'] + FakeModel.expect :seed, true, ['dependent on nested'] subject.invoke + + FakeModel.verify end end describe "after with no block given" do subject { Rake::Task['db:seed:no_block'] } it "runs the dependencies" do - FakeModel.should_receive(:seed).with('dependency').once.ordered + FakeModel.expect :seed, true, ['dependency'] subject.invoke + + FakeModel.verify end end describe "let" do - it "does something" do + describe "evaluates dependencies in order" do + subject { Rake::Task['db:seed:reference_memos'] } + + it "runs the dependencies in order" do + FakeModel.expect :seed, true, ['with_inline_memo'] + FakeModel.expect :seed, true, ['with_block_memo'] + FakeModel.expect :calling_let, true, ['BLOCK_LET'] + FakeModel.expect :calling_let, true, ['INLINE_LET'] + + def FakeModel.calling_let!(*args); end + def FakeModel.calling_method(*args); end + + subject.invoke + + FakeModel.verify + end end + + describe "a previously defined method" do + + let(:runner) { Seedbank::Runner.new } + + before { runner.let(:existing) {} } + + %w(__eigenclass existing let let evaluate after).each do |name| + it 'raises ArgumentError' do + assert_raises(ArgumentError, Regexp.new(name)) do + runner.let(name) + end + end + end + end + end + + describe "let!" do + + describe "evaluates dependencies in order" do + + subject { Rake::Task['db:seed:reference_memos'] } + + it "runs the dependencies in order" do + FakeModel.expect :calling_let!, true, ['INLINE_LET!'] + FakeModel.expect :calling_let!, true, ['BLOCK_LET!'] + + def FakeModel.seed(*args); end + def FakeModel.calling_let(*args); end + def FakeModel.calling_method(*args); end + + subject.invoke + + FakeModel.verify + end + end + + end + + describe "defining an inline method" do + + describe "evaluates dependencies in order" do + + subject { Rake::Task['db:seed:reference_memos'] } + + it "runs the dependencies in order" do + FakeModel.expect :calling_method, true, ['inline_method'] + + def FakeModel.seed(*args); end + def FakeModel.calling_let(*args); end + def FakeModel.calling_let!(*args); end + + subject.invoke + + FakeModel.verify + end + end + end + end