-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration specs for deferred helpers.
- Loading branch information
1 parent
3a21e47
commit 81fd0fb
Showing
10 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'support/integration/deferred/payload_examples' | ||
|
||
RSpec.describe Spec::Models::Rocket do | ||
subject(:rocket) { described_class.new('Imp IV') } | ||
|
||
include Spec::Integration::Deferred::PayloadExamples | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rspec/sleeping_king_studios/deferred/examples' | ||
|
||
require 'support/sandbox' | ||
|
||
RSpec.describe RSpec::SleepingKingStudios::Deferred::Examples do | ||
let(:fixture_file) do | ||
%w[spec/integration/deferred/helpers_spec.fixture.rb] | ||
end | ||
let(:result) do | ||
Spec::Support::Sandbox.run(fixture_file) | ||
end | ||
let(:expected_examples) do | ||
<<~EXAMPLES.lines.map(&:strip) | ||
Spec::Models::Rocket#launch when the rocket has a basic payload should not change the previous payload | ||
Spec::Models::Rocket#launch when the rocket has a basic payload should set the payload | ||
Spec::Models::Rocket#launch when the rocket has a complex payload should set the payload | ||
Spec::Models::Rocket#payload is expected to be == {} | ||
EXAMPLES | ||
end | ||
|
||
it 'should apply the deferred examples', :aggregate_failures do | ||
expect(result.summary).to be == '4 examples, 0 failures' | ||
|
||
expect(result.example_descriptions).to be == expected_examples | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'support/integration/deferred' | ||
|
||
module Spec::Integration::Deferred | ||
module ShouldNotChangeThePreviousPayload | ||
include RSpec::SleepingKingStudios::Deferred::Examples | ||
|
||
let!(:previous_payload) { subject.payload } | ||
|
||
it 'should not change the previous payload' do | ||
launch_rocket(payload:) | ||
|
||
expect(previous_payload).to be == {} | ||
end | ||
end | ||
|
||
module WhenThePayloadIncludesABattery | ||
include RSpec::SleepingKingStudios::Deferred::Examples | ||
|
||
let(:payload) { super().merge(battery: true) } | ||
end | ||
|
||
module WhenThePayloadIncludesASolarArray | ||
include RSpec::SleepingKingStudios::Deferred::Examples | ||
|
||
let(:payload) { super().merge(solar_array: true) } | ||
end | ||
|
||
module WhenThePayloadIncludesExperiments | ||
include RSpec::SleepingKingStudios::Deferred::Examples | ||
|
||
let(:payload) { super().merge(experiments: true) } | ||
end | ||
|
||
module PayloadExamples | ||
include RSpec::SleepingKingStudios::Deferred::Examples | ||
|
||
describe '#launch' do | ||
let(:launch_site) { 'KSC' } | ||
let(:payload) { {} } | ||
|
||
def launch_rocket(**options) | ||
subject.launch(launch_site:, **options) | ||
end | ||
|
||
context 'when the rocket has a basic payload' do | ||
include Spec::Integration::Deferred::WhenThePayloadIncludesABattery | ||
include Spec::Integration::Deferred::ShouldNotChangeThePreviousPayload | ||
|
||
let(:expected) { { battery: true } } | ||
|
||
it 'should set the payload' do | ||
expect { launch_rocket(payload:) } | ||
.to change(rocket, :payload) | ||
.to be == expected | ||
end | ||
end | ||
|
||
context 'when the rocket has a complex payload' do | ||
include Spec::Integration::Deferred::WhenThePayloadIncludesABattery | ||
include Spec::Integration::Deferred::WhenThePayloadIncludesASolarArray | ||
include Spec::Integration::Deferred::WhenThePayloadIncludesExperiments | ||
|
||
let(:expected) do | ||
{ battery: true, experiments: true, solar_array: true } | ||
end | ||
|
||
it 'should set the payload' do | ||
expect { launch_rocket(payload:) } | ||
.to change(rocket, :payload) | ||
.to be == expected | ||
end | ||
end | ||
end | ||
|
||
describe '#payload' do | ||
it { expect(subject.payload).to be == {} } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters