-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jobready/add-original-to-outcome
Add original option to RulesEngine::Outcome
- Loading branch information
Showing
4 changed files
with
187 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
class RulesEngine::Outcome | ||
attr_accessor :name, :values, :reference | ||
attr_accessor :name, | ||
:values, | ||
:reference, | ||
:original | ||
|
||
def initialize(options = {}) | ||
@name = options.fetch(:name) | ||
@values = options.fetch(:values) | ||
@reference = options.fetch(:reference, nil) | ||
@original = options.fetch(:original, nil) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,83 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Outcome' do | ||
describe RulesEngine::Outcome do | ||
describe '.new' do | ||
subject { described_class.new(options) } | ||
|
||
context 'Constructing a new instance from a hash' do | ||
context 'where only required arguments are provided' do | ||
let(:options) do | ||
{ | ||
name: 'an outcome', | ||
values: [{ parameter: 'some parameter', reference: 'some reference' }], | ||
} | ||
end | ||
|
||
let(:outcome) do | ||
RulesEngine::Outcome.new(name: 'some outcome', | ||
reference: 'outcome_reference', | ||
values: [{ parameter: 'some parameter', reference: 'some reference' }]) | ||
it 'sets name' do | ||
expect(subject.name).to eq('an outcome') | ||
end | ||
|
||
it 'sets values' do | ||
expect(subject.values).to eq([{ parameter: 'some parameter', reference: 'some reference' }]) | ||
end | ||
|
||
it 'does not set reference' do | ||
expect(subject.reference).to be_nil | ||
end | ||
|
||
it 'does not set original' do | ||
expect(subject.original).to be_nil | ||
end | ||
end | ||
|
||
specify { expect(outcome.name).to eq('some outcome') } | ||
specify { expect(outcome.reference).to eq('outcome_reference') } | ||
specify { expect(outcome.values.first[:parameter]).to eq('some parameter') } | ||
specify { expect(outcome.values.first[:reference]).to eq('some reference') } | ||
end | ||
context 'where all available arguments are provided' do | ||
let(:options) do | ||
{ | ||
name: 'an outcome', | ||
values: [{ parameter: 'some parameter', reference: 'some reference' }], | ||
reference: 'outcome_reference', | ||
original: 'original outcome', | ||
} | ||
end | ||
|
||
it 'sets name' do | ||
expect(subject.name).to eq('an outcome') | ||
end | ||
|
||
it 'sets values' do | ||
expect(subject.values).to eq([{ parameter: 'some parameter', reference: 'some reference' }]) | ||
end | ||
|
||
context 'Missing required arguments' do | ||
context 'name' do | ||
specify { expect { RulesEngine::Outcome.new(values: [{ parameter: 'some parameter', reference: 'some reference' }]) }.to raise_error } | ||
it 'sets reference' do | ||
expect(subject.reference).to eq('outcome_reference') | ||
end | ||
|
||
it 'sets original' do | ||
expect(subject.original).to eq('original outcome') | ||
end | ||
end | ||
|
||
context 'where name argument is missing' do | ||
let(:options) do | ||
{ | ||
values: [{ parameter: 'some parameter', reference: 'some reference' }], | ||
} | ||
end | ||
|
||
specify do | ||
expect { subject }.to raise_error(KeyError) | ||
end | ||
end | ||
context 'values' do | ||
specify { expect { RulesEngine::Outcome.new(name: 'some outcome') }.to raise_error } | ||
|
||
context 'where values argument is missing' do | ||
let(:options) do | ||
{ | ||
name: 'an outcome', | ||
} | ||
end | ||
|
||
specify do | ||
expect { subject }.to raise_error(KeyError) | ||
end | ||
end | ||
end | ||
end |