aye_commander 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ describe AyeCommander::Resultable::ClassMethods do
2
+ include_context :command
3
+
4
+ context '.result' do
5
+ it 'returns the command if command option is specified' do
6
+ expect(command.result(instance, :command)).to eq instance
7
+ end
8
+
9
+ it 'calls and returns .new_result with the complete hash if true option is specified' do
10
+ expect(instance).to receive(:to_hash).and_return(:stubbed)
11
+ expect(command).to receive(:new_result).with(:stubbed).and_return(:result)
12
+ expect(command.result(instance, true)).to eq :result
13
+ end
14
+
15
+ it 'calls and returns .new_result with the result hash if no option is specified' do
16
+ expect(instance).to receive(:to_result_hash).and_return(:stubbed)
17
+ expect(command).to receive(:new_result).with(:stubbed).and_return(:result)
18
+ expect(command.result(instance, false)).to eq :result
19
+ end
20
+ end
21
+
22
+ context '.new_result' do
23
+ let(:values) { { :@status => :success } }
24
+
25
+ it 'returns an instance of the result class' do
26
+ expect(command.new_result(values)).to be_an_instance_of result_class
27
+ end
28
+
29
+ it 'should contain the expected results' do
30
+ expect(command.new_result(values).to_hash).to eq values
31
+ end
32
+ end
33
+
34
+ context '.result_class' do
35
+ it 'returns the result class' do
36
+ expect(result_class).to be_an_instance_of Class
37
+ end
38
+
39
+ it 'defines the class under the Result const name' do
40
+ expect(result_class).to eq command.const_get('Result')
41
+ end
42
+
43
+ it 'only defines the class once' do
44
+ expect(result_class.object_id).to eq command.result_class.object_id
45
+ end
46
+
47
+ it 'includes the necessary result modules' do
48
+ expect(result_class).to include AyeCommander::Initializable
49
+ expect(result_class).to include AyeCommander::Inspectable
50
+ expect(result_class).to include AyeCommander::Status::Readable
51
+ expect(result_class).to include AyeCommander::Ivar::Readable
52
+ end
53
+
54
+ it 'extends the necessary result modules' do
55
+ expect(result_class.singleton_class).to include AyeCommander::Ivar::ClassMethods
56
+ end
57
+
58
+ it 'defines readers for the class' do
59
+ command.uses :variable
60
+ expect(result_class.new).to respond_to :variable
61
+ expect(result_class.new).to_not respond_to :variable=
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,38 @@
1
+ describe AyeCommander::Shareable::ClassMethods do
2
+ include_context :command
3
+
4
+ context '.included' do
5
+ it 'ensures that the includer has command methods available' do
6
+ expect(includer.ancestors).to include AyeCommander::Command
7
+ expect(includer.singleton_class.ancestors).to include AyeCommander::Command::ClassMethods
8
+ end
9
+
10
+ it 'ensure that even down the line the command methods are available' do
11
+ expect(includer2.ancestors).to include AyeCommander::Command
12
+ expect(includer2.singleton_class.ancestors).to include AyeCommander::Command::ClassMethods
13
+ end
14
+
15
+ it 'adds the needed instance variables to the further includers' do
16
+ includer.receives :hopefully_this
17
+ includer.succeeds_with :inclusion
18
+ expect(includer2.receives).to include :hopefully_this
19
+ expect(includer2.succeeds).to include :inclusion
20
+ expect(includer2.send(:hooks)).to be_empty
21
+ end
22
+ end
23
+
24
+ context '.inherited' do
25
+ it 'has access to the command class methods' do
26
+ expect(inheriter.ancestors).to include AyeCommander::Command
27
+ expect(inheriter.singleton_class.ancestors).to include AyeCommander::Command::ClassMethods
28
+ end
29
+
30
+ it 'adds the needed instance variables to the further inheriters' do
31
+ command.receives :hopefully_this
32
+ command.succeeds_with :inclusion
33
+ expect(inheriter.receives).to include :hopefully_this
34
+ expect(inheriter.succeeds).to include :inclusion
35
+ expect(inheriter.send(:hooks)).to be_empty
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,97 @@
1
+ describe AyeCommander::Status::ClassMethods do
2
+ include_context :command
3
+
4
+ context '.succeeds' do
5
+ it 'returns [:success] if nothing else has been set' do
6
+ expect(command.succeeds).to eq [:success]
7
+ end
8
+
9
+ it 'returns whathever the :@succeds class instance variable contains' do
10
+ command.instance_variable_set :@succeeds, %i(im a little teapot)
11
+ expect(command.succeeds).to eq %i(im a little teapot)
12
+ end
13
+ end
14
+
15
+ context '.suceeds_with' do
16
+ let(:args) { %i(succ1 succ2) }
17
+
18
+ before :each do
19
+ command.succeeds_with(*args)
20
+ end
21
+
22
+ it 'adds the values to the succeeds array' do
23
+ expect(command.succeeds).to eq %i(success succ1 succ2)
24
+ end
25
+
26
+ it 'allows consecutive succeeds' do
27
+ command.succeeds_with :potato
28
+ expect(command.succeeds).to eq %i(success succ1 succ2 potato)
29
+ end
30
+
31
+ it 'doesnt add repeated succeeds' do
32
+ command.succeeds_with(*args)
33
+ expect(command.succeeds).to eq %i(success succ1 succ2)
34
+ end
35
+
36
+ it 'removes :success from the array if called with the exclude_suceed option' do
37
+ command.succeeds_with exclude_success: true
38
+ expect(command.succeeds).to eq args
39
+ end
40
+ end
41
+ end
42
+
43
+ describe AyeCommander::Status::Readable do
44
+ include_context :command
45
+
46
+ context 'when included' do
47
+ it 'adds #status method' do
48
+ expect(instance).to respond_to :status
49
+ end
50
+ end
51
+
52
+ context '#success?' do
53
+ it 'returns true if nothing else is set' do
54
+ expect(instance.success?).to be true
55
+ end
56
+
57
+ it 'returns true if status is contained in the succeeds array' do
58
+ command.succeeds_with :taco
59
+ instance.status = :taco
60
+ expect(instance.success?).to be true
61
+ end
62
+
63
+ it 'returns false if status is NOT contained in the succeeds array' do
64
+ command.succeeds_with :taco, exclude_success: true
65
+ instance.status = :success
66
+ expect(instance.success?).to be false
67
+ end
68
+ end
69
+
70
+ context '#failure?' do
71
+ it 'is the boolean opposite of success' do
72
+ expect(instance.failure?).to be false
73
+ end
74
+ end
75
+ end
76
+
77
+ describe AyeCommander::Status::Writeable do
78
+ include_context :command
79
+
80
+ context 'when included' do
81
+ it 'adds #status= method' do
82
+ expect(instance).to respond_to :status=
83
+ end
84
+ end
85
+
86
+ context '#fail!' do
87
+ it 'fails the command with :failure' do
88
+ instance.fail!
89
+ expect(instance.status).to eq :failure
90
+ end
91
+
92
+ it 'fails the command with specified status' do
93
+ instance.fail!(:meltdown)
94
+ expect(instance.status).to eq :meltdown
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ describe AyeCommander do
2
+ it 'should exist' do
3
+ expect(AyeCommander).to be
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ else
5
+ require 'simplecov'
6
+ SimpleCov.start do
7
+ add_filter 'spec/'
8
+ end
9
+ end
10
+
11
+ require 'pry'
12
+ require 'aye_commander'
13
+
14
+ # Shared context for command tests
15
+ shared_context :command do
16
+ let(:command) do
17
+ Class.new do
18
+ include AyeCommander::Command
19
+ define_method(:call) {}
20
+ end
21
+ end
22
+
23
+ let(:commandsc) { command.singleton_class }
24
+ let(:instance) { command.new }
25
+ let(:result) { command.result_class.new }
26
+ let(:result_class) { command.result_class }
27
+
28
+ let(:inheriter) { Class.new(command) }
29
+ let(:includer) { Module.new.send(:include, AyeCommander::Command) }
30
+ let(:includer2) { Module.new.send(:include, includer) }
31
+ end
32
+
33
+ # Shared context for commander tests
34
+ shared_context :commander do
35
+ let(:command) do
36
+ Class.new do
37
+ include AyeCommander::Command
38
+ define_method(:call) {}
39
+ end
40
+ end
41
+
42
+ let(:commander) { Class.new.send(:include, AyeCommander::Commander) }
43
+ let(:instance) { commander.new }
44
+ let(:commandi) { command.new }
45
+
46
+ let(:includer) { Module.new.send(:include, AyeCommander::Commander) }
47
+ let(:includer2) { Module.new.send(:include, includer) }
48
+ let(:inheriter) { Class.new(commander) }
49
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aye_commander
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - pyzlnar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem that helps to write commands in ruby.
14
+ email: pyzlnar@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.adoc
21
+ - lib/aye_commander.rb
22
+ - lib/aye_commander/abortable.rb
23
+ - lib/aye_commander/callable.rb
24
+ - lib/aye_commander/command.rb
25
+ - lib/aye_commander/commander.rb
26
+ - lib/aye_commander/errors.rb
27
+ - lib/aye_commander/hookable.rb
28
+ - lib/aye_commander/initializable.rb
29
+ - lib/aye_commander/inspectable.rb
30
+ - lib/aye_commander/ivar.rb
31
+ - lib/aye_commander/limitable.rb
32
+ - lib/aye_commander/resultable.rb
33
+ - lib/aye_commander/shareable.rb
34
+ - lib/aye_commander/status.rb
35
+ - lib/aye_commander/version.rb
36
+ - spec/aye_commander/abortable_spec.rb
37
+ - spec/aye_commander/callable_spec.rb
38
+ - spec/aye_commander/command_spec.rb
39
+ - spec/aye_commander/commander_spec.rb
40
+ - spec/aye_commander/errors_spec.rb
41
+ - spec/aye_commander/hookable_spec.rb
42
+ - spec/aye_commander/initializable_spec.rb
43
+ - spec/aye_commander/inspectable_spec.rb
44
+ - spec/aye_commander/ivar_spec.rb
45
+ - spec/aye_commander/limitable_spec.rb
46
+ - spec/aye_commander/resultable_spec.rb
47
+ - spec/aye_commander/shareable_spec.rb
48
+ - spec/aye_commander/status_spec.rb
49
+ - spec/aye_commander_spec.rb
50
+ - spec/spec_helper.rb
51
+ homepage: https://github.com/pyzlnar/aye_commander
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 2.0.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.4.8
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: A simple command pattern gem
75
+ test_files:
76
+ - spec/aye_commander/abortable_spec.rb
77
+ - spec/aye_commander/callable_spec.rb
78
+ - spec/aye_commander/command_spec.rb
79
+ - spec/aye_commander/commander_spec.rb
80
+ - spec/aye_commander/errors_spec.rb
81
+ - spec/aye_commander/hookable_spec.rb
82
+ - spec/aye_commander/initializable_spec.rb
83
+ - spec/aye_commander/inspectable_spec.rb
84
+ - spec/aye_commander/ivar_spec.rb
85
+ - spec/aye_commander/limitable_spec.rb
86
+ - spec/aye_commander/resultable_spec.rb
87
+ - spec/aye_commander/shareable_spec.rb
88
+ - spec/aye_commander/status_spec.rb
89
+ - spec/aye_commander_spec.rb
90
+ - spec/spec_helper.rb