From 702846839b732201a0d0e06aa07b34ef7b282b5c Mon Sep 17 00:00:00 2001 From: Erran Carey Date: Tue, 16 Sep 2014 19:33:15 -0500 Subject: [PATCH 1/3] Test after hook order in the Test::Mapper spec Validate that Cucumber::Core::Test::Mapper returns adds after hooks in reverse order. See #64. --- spec/cucumber/core/test/mapper_spec.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spec/cucumber/core/test/mapper_spec.rb b/spec/cucumber/core/test/mapper_spec.rb index 2728f072..a54b77e9 100644 --- a/spec/cucumber/core/test/mapper_spec.rb +++ b/spec/cucumber/core/test/mapper_spec.rb @@ -97,15 +97,17 @@ def test_step(test_step, mapper) it "adds hooks in the right order" do log = double allow(mappings).to receive(:test_case) do |test_case, mapper| - mapper.before { log.before } - mapper.after { log.after } + mapper.before { log.before_hook } + mapper.after { log.after_hook_1 } + mapper.after { log.after_hook_2 } end mapped_step = test_step.with_mapping { log.step } test_case = Case.new([mapped_step], source) - expect( log ).to receive(:before).ordered + expect( log ).to receive(:before_hook).ordered expect( log ).to receive(:step).ordered - expect( log ).to receive(:after).ordered + expect( log ).to receive(:after_hook_2).ordered + expect( log ).to receive(:after_hook_1).ordered allow(receiver).to receive(:test_case).and_yield(receiver) allow(receiver).to receive(:test_step) do |test_step| @@ -128,7 +130,7 @@ def test_step(test_step, mapper) expect( scenario ).to receive(:describe_to) expect( visitor ).to receive(:before_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:121") + expect( hook.location.to_s ).to eq("#{__FILE__}:123") end test_step.describe_source_to(visitor, args) end @@ -148,7 +150,7 @@ def test_step(test_step, mapper) expect( scenario ).to receive(:describe_to) expect( visitor ).to receive(:after_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:141") + expect( hook.location.to_s ).to eq("#{__FILE__}:143") end test_step.describe_source_to(visitor, args) end @@ -168,7 +170,7 @@ def test_step(test_step, mapper) expect( visitor ).to receive(:step).ordered expect( visitor ).to receive(:after_step_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:160") + expect( hook.location.to_s ).to eq("#{__FILE__}:162") end.once.ordered expect( visitor ).to receive(:step).ordered test_case.describe_to mapper @@ -180,4 +182,3 @@ def test_step(test_step, mapper) end end end - From c5779e1185ea903202c3f4286e081f159d1cb12d Mon Sep 17 00:00:00 2001 From: Erran Carey Date: Tue, 16 Sep 2014 19:46:49 -0500 Subject: [PATCH 2/3] Use #unshift instead of #<< to add new after hooks Fix #64 by using `Array#unshift` which prepends vs. `Array#<<` which appends. --- lib/cucumber/core/test/mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cucumber/core/test/mapper.rb b/lib/cucumber/core/test/mapper.rb index aa197003..8925a346 100644 --- a/lib/cucumber/core/test/mapper.rb +++ b/lib/cucumber/core/test/mapper.rb @@ -65,7 +65,7 @@ def before(&block) # Run this block of code after the scenario def after(&block) - mapper.after_hooks << hook_factory.after(block) + mapper.after_hooks.unshift(hook_factory.after(block)) self end From c0ce59563bc5acc3f24d4a321711c1625cb735b6 Mon Sep 17 00:00:00 2001 From: Erran Carey Date: Tue, 16 Sep 2014 20:07:34 -0500 Subject: [PATCH 3/3] Validate the before hook order as well --- spec/cucumber/core/test/mapper_spec.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/cucumber/core/test/mapper_spec.rb b/spec/cucumber/core/test/mapper_spec.rb index a54b77e9..f3f7fd43 100644 --- a/spec/cucumber/core/test/mapper_spec.rb +++ b/spec/cucumber/core/test/mapper_spec.rb @@ -97,15 +97,17 @@ def test_step(test_step, mapper) it "adds hooks in the right order" do log = double allow(mappings).to receive(:test_case) do |test_case, mapper| - mapper.before { log.before_hook } + mapper.before { log.before_hook_1 } + mapper.before { log.before_hook_2 } mapper.after { log.after_hook_1 } mapper.after { log.after_hook_2 } end - mapped_step = test_step.with_mapping { log.step } + mapped_step = test_step.with_mapping { log.step_1 } test_case = Case.new([mapped_step], source) - expect( log ).to receive(:before_hook).ordered - expect( log ).to receive(:step).ordered + expect( log ).to receive(:before_hook_1).ordered + expect( log ).to receive(:before_hook_2).ordered + expect( log ).to receive(:step_1).ordered expect( log ).to receive(:after_hook_2).ordered expect( log ).to receive(:after_hook_1).ordered @@ -130,7 +132,7 @@ def test_step(test_step, mapper) expect( scenario ).to receive(:describe_to) expect( visitor ).to receive(:before_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:123") + expect( hook.location.to_s ).to eq("#{__FILE__}:125") end test_step.describe_source_to(visitor, args) end @@ -150,7 +152,7 @@ def test_step(test_step, mapper) expect( scenario ).to receive(:describe_to) expect( visitor ).to receive(:after_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:143") + expect( hook.location.to_s ).to eq("#{__FILE__}:145") end test_step.describe_source_to(visitor, args) end @@ -170,7 +172,7 @@ def test_step(test_step, mapper) expect( visitor ).to receive(:step).ordered expect( visitor ).to receive(:after_step_hook) do |hook, hook_args| expect( args ).to eq(hook_args) - expect( hook.location.to_s ).to eq("#{__FILE__}:162") + expect( hook.location.to_s ).to eq("#{__FILE__}:164") end.once.ordered expect( visitor ).to receive(:step).ordered test_case.describe_to mapper