diff options
| author | Teddy Wing | 2017-08-02 11:56:03 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-08-02 11:58:34 +0200 |
| commit | 9c485dce0e738dc94ad09db270f35c367264b5c5 (patch) | |
| tree | 1e1cc0a1ed496d16c33dd860466f3e4f490fd037 | |
| parent | e78c3241049cf29028138eee95f2af55d8fcfdd0 (diff) | |
| download | chouette-core-9c485dce0e738dc94ad09db270f35c367264b5c5.tar.bz2 | |
Import spec: Convert helper methods to shared examples
At Robert's suggestion, convert these methods to RSpec shared examples.
I had thought about using shared examples when I originally wanted to
write these tests, but was trying to get things working quickly and
couldn't figure out how to use them at the time, so I went with
something that seemed obvious to me and worked. Now we can take
advantage of the testing DSL available.
Refs #3509, #3511
| -rw-r--r-- | spec/models/import_spec.rb | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb index 0a484f906..aa43d3f1b 100644 --- a/spec/models/import_spec.rb +++ b/spec/models/import_spec.rb @@ -45,10 +45,10 @@ RSpec.describe Import, :type => :model do end describe "#child_change" do - it "updates :status to failed when child status indicates failure" do - def updates_status_to_failed_when_child_status_indicates_failure( - failure_status - ) + shared_examples( + "updates :status to failed when child status indicates failure" + ) do |failure_status| + it "updates :status to failed when child status indicates failure" do workbench_import = build_stubbed(:workbench_import) allow(workbench_import).to receive(:update) @@ -62,12 +62,21 @@ RSpec.describe Import, :type => :model do workbench_import.child_change(netex_import) end - - updates_status_to_failed_when_child_status_indicates_failure('failed') - updates_status_to_failed_when_child_status_indicates_failure('aborted') - updates_status_to_failed_when_child_status_indicates_failure('canceled') end + include_examples( + "updates :status to failed when child status indicates failure", + "failed" + ) + include_examples( + "updates :status to failed when child status indicates failure", + "aborted" + ) + include_examples( + "updates :status to failed when child status indicates failure", + "canceled" + ) + it "updates :status to successful when #ready?" do workbench_import = build_stubbed( :workbench_import, @@ -101,8 +110,10 @@ RSpec.describe Import, :type => :model do workbench_import.child_change(netex_import) end - it "doesn't update :status if parent import status is finished" do - def does_not_receive_update_when_status(finished_status) + shared_examples( + "doesn't update :status if parent import status is finished" + ) do |finished_status| + it "doesn't update :status if parent import status is finished" do workbench_import = build_stubbed( :workbench_import, total_steps: 2, @@ -115,12 +126,24 @@ RSpec.describe Import, :type => :model do workbench_import.child_change(child) end - - does_not_receive_update_when_status('successful') - does_not_receive_update_when_status('failed') - does_not_receive_update_when_status('aborted') - does_not_receive_update_when_status('canceled') end + + include_examples( + "doesn't update :status if parent import status is finished", + "successful" + ) + include_examples( + "doesn't update :status if parent import status is finished", + "failed" + ) + include_examples( + "doesn't update :status if parent import status is finished", + "aborted" + ) + include_examples( + "doesn't update :status if parent import status is finished", + "canceled" + ) end describe "#ready?" do |
