spec/lib/command_spec.rb in simple_service-1.0.2 vs spec/lib/command_spec.rb in simple_service-1.2.5
- old
+ new
@@ -1,44 +1,51 @@
require 'spec_helper'
describe SimpleService::Command do
class ValidCommand < SimpleService::Command
-
expects :foo, :bar
returns :bar, :baz
-
- def execute
+ def call
context.merge!(
bar: 'modified',
baz: 'blah'
)
end
+ end
+ class InvalidReturnCommand < SimpleService::Command
+ expects :foo
+ returns :foo, :baz
+ def call; true; end
end
- class NoExecuteDefinedCommand < SimpleService::Command
+
+ class CallNotDefinedCommand < SimpleService::Command
end
- describe '#execute' do
+ describe '#call' do
context 'when #returns is not empty' do
it 'returns the correct keys from the context' do
expect(
- ValidCommand.new(foo: 'blah', bar: 'meh').execute
+ ValidCommand.new(foo: 'blah', bar: 'meh').call
).to eql(bar: 'modified', baz: 'blah')
end
end
context 'raises error' do
- it 'when command does not define an execute method' do
+ it 'when command does not define an call method' do
expect {
- NoExecuteDefinedCommand.new.execute
- }.to raise_error(
- SimpleService::ExecuteNotDefinedError,
- 'NoExecuteDefinedCommand - does not define an execute method'
- )
+ CallNotDefinedCommand.new.call
+ }.to raise_error(SimpleService::CallNotDefinedError)
+ end
+
+ it 'when command attempts to return a key that doesnt exist' do
+ expect {
+ InvalidReturnCommand.new.call
+ }.to raise_error(SimpleService::ReturnKeyError)
end
end
end