test/lib/seedbank/dsl_test.rb in seedbank-0.2.1 vs test/lib/seedbank/dsl_test.rb in seedbank-0.3.0.pre

- old
+ new

@@ -52,11 +52,11 @@ describe "seeds_root" do let(:seeds_root) { '/my/seeds/directory' } - subject { Seedbank::DSL.seeds_root } + subject { Seedbank::DSL.send(:seeds_root) } it "returns a Pathname" do flexmock(Seedbank).should_receive(:seeds_root).and_return(seeds_root).by_default subject.must_equal Pathname.new(seeds_root) @@ -109,16 +109,10 @@ Seedbank::DSL.define_seed_task(seed_file, name => dependencies) Rake::Task[name].wont_be_nil end - it "sets Rake Task dependencies" do - Seedbank::DSL.define_seed_task(seed_file, name => dependencies) - - Rake::Task[name].prerequisite_tasks.must_equal dependencies.map { |dependency| Rake::Task[dependency] } - end - it "sets Rake Task description" do Seedbank::DSL.define_seed_task(seed_file, name => dependencies) Rake::Task[name].comment.must_equal "Load the seed data from #{seed_file}" end @@ -128,19 +122,59 @@ flexmock(FakeModel).should_receive(:seed).with('development:users').once.ordered Rake::Task[name].invoke end + + describe "when db:abort_if_pending_migrations exists" do + it "sets Rake Task dependencies" do + Seedbank::DSL.define_seed_task(seed_file, name => dependencies) + expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] } + expected_dependencies << Rake::Task['db:abort_if_pending_migrations'] + + Rake::Task[name].prerequisite_tasks.must_equal expected_dependencies + end + end + + describe "when db:abort_if_pending_migrations does not exist" do + it "sets Rake Task dependencies" do + flexmock(Rake::Task).should_receive(:task_defined?).and_return(false).by_default + + Seedbank::DSL.define_seed_task(seed_file, name => dependencies) + + Rake::Task[name].prerequisite_tasks.must_equal dependencies.map { |dependency| Rake::Task[dependency] } + end + end end describe "override_seed_task" do - let(:arguments) { 'my_task' } + describe "when no task exists to override" do - it "calls Rake::TaskManager#override_task" do - block = proc {} - flexmock(Rake.application).should_receive(:override_task).with(arguments, block).once + let(:name) { 'my_task' } + let(:dependencies) { ['seedy:users'] } - Seedbank::DSL.override_seed_task(arguments, &block) + it "creates a new task" do + Seedbank::DSL.override_seed_task(name => dependencies) + + Rake::Task[name].wont_be_nil + end + + it "applies the dependencies" do + expected_dependencies = dependencies.map { |dependency| Rake::Task[dependency] } + Seedbank::DSL.override_seed_task(name => dependencies) + + Rake::Task[name].prerequisite_tasks.must_equal expected_dependencies + end + + it "applies the description" do + description = 'Expected Description' + Rake.application.last_description = description + + Seedbank::DSL.override_seed_task(name => dependencies) + + Rake::Task[name].full_comment.must_equal description + end end + end end