Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce duplication with Processor::API::Responder
- Loading branch information
Showing
6 changed files
with
131 additions
and
68 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
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
47 changes: 47 additions & 0 deletions
47
spec/unit/substation/processor/api/responder/included_spec.rb
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,47 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Processor::API::Responder, '#included' do | ||
subject { klass.new } | ||
|
||
let(:base) { Processor::Evaluator::Result } | ||
let(:success) { base::Success.new(output) } | ||
let(:error) { base::Failure.new(output) } | ||
let(:output) { mock } | ||
|
||
context 'when private #respond_with is not implemented' do | ||
let(:klass) do | ||
Class.new do | ||
include Processor::API::Responder.new(Processor::Evaluator::Result) | ||
end | ||
end | ||
|
||
[ :success, :error ].each do |method_name| | ||
it "raises NotImplementedError when calling ##{method_name}" do | ||
msg = "#{subject.class}#respond_with must be implemented" | ||
expect { | ||
subject.public_send(method_name, output) | ||
}.to raise_error(NotImplementedError, msg) | ||
end | ||
end | ||
end | ||
|
||
context 'when private #respond_with is implemented' do | ||
let(:klass) do | ||
Class.new do | ||
include Processor::API::Responder.new(Processor::Evaluator::Result) | ||
private | ||
def respond_with(klass, output) | ||
klass.new(output) | ||
end | ||
end | ||
end | ||
|
||
[ :success, :error ].each do |method_name| | ||
it "defines public ##{method_name} on its host" do | ||
expect(subject.public_send(method_name, output)).to eql(send(method_name)) | ||
end | ||
end | ||
end | ||
end |