mithril-specs 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +31 -0
- data/README.md +0 -0
- data/spec/mithril/controllers/_text_controller_helper.rb +81 -0
- data/spec/mithril/controllers/abstract_controller_helper.rb +118 -0
- data/spec/mithril/controllers/mixins/actions_base_helper.rb +121 -0
- data/spec/mithril/controllers/mixins/help_actions_helper.rb +111 -0
- data/spec/mithril/controllers/proxy_controller_helper.rb +111 -0
- data/spec/mithril/mixin_helper.rb +54 -0
- data/spec/mithril/spec_helper.rb +11 -0
- metadata +101 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## Development Versions
|
2
|
+
|
3
|
+
#### Version 0.2.0
|
4
|
+
* Implemented ProxyController
|
5
|
+
|
6
|
+
#### Version 0.1.2
|
7
|
+
* Added HelpActions mixin
|
8
|
+
|
9
|
+
#### Version 0.1.1
|
10
|
+
* Added logger property to Mithril module
|
11
|
+
|
12
|
+
#### Version 0.1.0
|
13
|
+
* Implemented AbstractController
|
14
|
+
|
15
|
+
#### Version 0.0.4
|
16
|
+
* Renamed ActionMixin to MixinWithActions for clarity
|
17
|
+
* Improved specs for Mixin, MixinWithActions
|
18
|
+
|
19
|
+
#### Version 0.0.3
|
20
|
+
* Implemented Mithril::Parsers::SimpleParser
|
21
|
+
|
22
|
+
#### Version 0.0.2
|
23
|
+
* Implemented Mithril::Controllers::Mixins::ActionsBase
|
24
|
+
* Implemented Mithril::Request
|
25
|
+
* Added and monkey-patched RSpec Matchers
|
26
|
+
|
27
|
+
#### Version 0.0.1
|
28
|
+
* Implemented Mithril::Mixin
|
29
|
+
|
30
|
+
#### Version 0.0.0
|
31
|
+
* Smoke test
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# spec/controllers/text_controller_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/controllers/abstract_controller_helper'
|
4
|
+
|
5
|
+
shared_examples_for "Mithril::Controllers::_TextController" do
|
6
|
+
it_behaves_like Mithril::Controllers::AbstractController
|
7
|
+
|
8
|
+
let :input do "text input"; end
|
9
|
+
|
10
|
+
describe :parser do
|
11
|
+
specify { expect(instance.parser).to be_a Mithril::Parsers::SimpleParser }
|
12
|
+
end # describe
|
13
|
+
|
14
|
+
describe :parse_command do
|
15
|
+
specify { expect(instance.parse_command input).to be_a Array }
|
16
|
+
|
17
|
+
specify "returns nil" do
|
18
|
+
command, args = instance.parse_command input
|
19
|
+
expect(command).to be nil
|
20
|
+
end # specify
|
21
|
+
end # describe
|
22
|
+
|
23
|
+
describe :command_missing do
|
24
|
+
specify "returns the text with a helpful message" do
|
25
|
+
output = instance.command_missing input
|
26
|
+
expect(output).to match /don't know how/
|
27
|
+
expect(output).to match /#{input}/
|
28
|
+
end # specify
|
29
|
+
end # describe
|
30
|
+
|
31
|
+
describe :invoke_command do
|
32
|
+
specify "returns the text with a helpful message" do
|
33
|
+
output = instance.invoke_command input
|
34
|
+
expect(output).to match /don't know how/
|
35
|
+
expect(output).to match /#{input}/
|
36
|
+
end # specify
|
37
|
+
end # describe
|
38
|
+
|
39
|
+
context "with actions defined" do
|
40
|
+
let :command do FactoryGirl.generate :action_key; end
|
41
|
+
let :arguments do %w(arguments for command); end
|
42
|
+
|
43
|
+
before :each do
|
44
|
+
described_class.define_action command do |session, args| args.join(' '); end
|
45
|
+
end # before each
|
46
|
+
|
47
|
+
specify { expect(instance.can_invoke? command.to_s).to be true }
|
48
|
+
|
49
|
+
describe :invoke_command do
|
50
|
+
let :text do "#{command} #{arguments.join(' ')}"; end
|
51
|
+
|
52
|
+
specify "invokes matching action" do
|
53
|
+
instance.should_receive(:invoke_action).with(command, arguments).and_call_original
|
54
|
+
instance.should_receive(:"action_#{command}").with(request.session, arguments).and_call_original
|
55
|
+
instance.invoke_command text
|
56
|
+
end # specify
|
57
|
+
|
58
|
+
specify { expect(instance.invoke_command text).to eq arguments.join(' ') }
|
59
|
+
|
60
|
+
context "with a non-matching command" do
|
61
|
+
let :non_matching do FactoryGirl.generate :action_key; end
|
62
|
+
|
63
|
+
specify { expect(instance.invoke_command non_matching.to_s).to match /don't know how/i }
|
64
|
+
end # context
|
65
|
+
end # describe
|
66
|
+
end # context
|
67
|
+
|
68
|
+
describe "empty actions" do
|
69
|
+
def self.input
|
70
|
+
chars, words = [*"a".."z", *"0".."9"], [""] * 5
|
71
|
+
5.times do |i|
|
72
|
+
word = ""
|
73
|
+
(6 + rand(10)).times do word << chars[rand(36)]; end
|
74
|
+
words[i] = word
|
75
|
+
end # times
|
76
|
+
words.join " "
|
77
|
+
end # helper input
|
78
|
+
|
79
|
+
it_behaves_like "Mithril::Controllers::AbstractController#empty_actions", input
|
80
|
+
end # describe
|
81
|
+
end # describe
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# spec/mithril/controllers/abstract_controller_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/controllers/mixins/actions_base_helper'
|
4
|
+
|
5
|
+
require 'mithril/controllers/abstract_controller'
|
6
|
+
|
7
|
+
shared_examples_for Mithril::Controllers::AbstractController do
|
8
|
+
it_behaves_like Mithril::Controllers::Mixins::ActionsBase
|
9
|
+
|
10
|
+
describe :constructor do
|
11
|
+
specify { expect(described_class).to construct.with(1).arguments }
|
12
|
+
specify { expect { described_class.new request }.not_to raise_error }
|
13
|
+
end # describe
|
14
|
+
|
15
|
+
describe :parser do
|
16
|
+
specify { expect(instance).to respond_to(:parser).with(0).arguments }
|
17
|
+
end # describe
|
18
|
+
|
19
|
+
describe :parse_command do
|
20
|
+
let :input do Object.new; end
|
21
|
+
|
22
|
+
specify { expect(instance).to respond_to(:parse_command).with(1).arguments }
|
23
|
+
specify "delegates to the parser" do
|
24
|
+
instance.parser.should_receive(:parse_command).with(input)
|
25
|
+
instance.parse_command(input)
|
26
|
+
end # specify
|
27
|
+
end # describe
|
28
|
+
|
29
|
+
describe :command_missing do
|
30
|
+
let :input do Object.new; end
|
31
|
+
|
32
|
+
specify { expect(instance).to respond_to(:command_missing).with(1).arguments }
|
33
|
+
end # describe
|
34
|
+
|
35
|
+
describe :commands do
|
36
|
+
specify { expect(instance).to respond_to(:commands).with(0).arguments }
|
37
|
+
specify { expect(instance.commands).to be_a Array }
|
38
|
+
end # describe
|
39
|
+
|
40
|
+
describe :has_command? do
|
41
|
+
specify { expect(instance).to respond_to(:has_command?).with(1).arguments }
|
42
|
+
specify { expect(instance).not_to have_command FactoryGirl.generate :action_key }
|
43
|
+
end # describe
|
44
|
+
|
45
|
+
describe :can_invoke? do
|
46
|
+
specify { expect(instance).to respond_to(:can_invoke?).with(1).arguments }
|
47
|
+
specify { expect(instance.can_invoke? FactoryGirl.generate(:action_key).to_s).
|
48
|
+
to eq false }
|
49
|
+
end # describe
|
50
|
+
|
51
|
+
describe :invoke_command do
|
52
|
+
specify { expect(instance).to respond_to(:invoke_command).with(1).arguments }
|
53
|
+
end # describe
|
54
|
+
|
55
|
+
context "with actions defined" do
|
56
|
+
let :command do FactoryGirl.generate :action_key; end
|
57
|
+
|
58
|
+
before :each do described_class.define_action command do |session, args|; end; end
|
59
|
+
|
60
|
+
specify { expect(instance.commands).to include command.to_s.gsub('_',' ') }
|
61
|
+
|
62
|
+
specify { expect(instance).to have_action command }
|
63
|
+
|
64
|
+
describe "inheriting defined actions" do
|
65
|
+
let :descendant_class do Class.new described_class; end
|
66
|
+
let :instance do descendant_class.new request; end
|
67
|
+
|
68
|
+
specify { expect(instance).to have_action command }
|
69
|
+
end # describe
|
70
|
+
end # context
|
71
|
+
|
72
|
+
describe "empty actions" do
|
73
|
+
describe :allow_empty_action? do
|
74
|
+
specify { expect(instance).to respond_to(:allow_empty_action?).with(0).arguments }
|
75
|
+
end # describe
|
76
|
+
end # describe
|
77
|
+
end # shared examples
|
78
|
+
|
79
|
+
shared_examples_for "Mithril::Controllers::AbstractController#empty_actions" do |input|
|
80
|
+
let :arguments do instance.parse_command(input)[1]; end
|
81
|
+
|
82
|
+
before :each do
|
83
|
+
if instance.has_action? :""
|
84
|
+
instance.stub :_action do |session, arguments| arguments; end
|
85
|
+
else
|
86
|
+
described_class.send :define_action, :"" do |session, arguments| arguments; end
|
87
|
+
end # if-else
|
88
|
+
end # before each
|
89
|
+
|
90
|
+
context "disallowing empty actions" do
|
91
|
+
before :each do instance.stub :allow_empty_action? do false; end; end
|
92
|
+
|
93
|
+
specify { expect(instance.allow_empty_action?).to be false }
|
94
|
+
|
95
|
+
specify "rejects arbitrary input" do
|
96
|
+
expect(instance.can_invoke? input).to be false
|
97
|
+
end # describe
|
98
|
+
end # context
|
99
|
+
|
100
|
+
context "allowing empty actions" do
|
101
|
+
before :each do instance.stub :allow_empty_action? do true; end; end
|
102
|
+
|
103
|
+
specify { expect(instance.allow_empty_action?).to be true }
|
104
|
+
|
105
|
+
specify "accepts arbitrary input" do
|
106
|
+
expect(instance.can_invoke? input).to be true
|
107
|
+
end # specify
|
108
|
+
|
109
|
+
specify "calls invoke action on empty action" do
|
110
|
+
instance.should_receive(:invoke_action).with(:"", arguments).and_call_original
|
111
|
+
instance.invoke_command input
|
112
|
+
end # specify
|
113
|
+
|
114
|
+
specify "returns the input" do
|
115
|
+
expect(instance.invoke_command input).to eq arguments
|
116
|
+
end # specify
|
117
|
+
end # context
|
118
|
+
end # shared examples
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# spec/mithril/controllers/mixins/actions_base_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/controllers/mixins/actions_base'
|
4
|
+
require 'mithril/request'
|
5
|
+
|
6
|
+
shared_examples_for Mithril::Controllers::Mixins::ActionsBase do
|
7
|
+
let :command do FactoryGirl.generate :action_key; end
|
8
|
+
|
9
|
+
specify { expect(instance).not_to respond_to :"action_#{command}" }
|
10
|
+
|
11
|
+
describe "self.define_action" do
|
12
|
+
specify { expect(described_class).to respond_to(:define_action).
|
13
|
+
with(1..2).arguments.and.a_block }
|
14
|
+
end # describe
|
15
|
+
|
16
|
+
describe "self.actions" do
|
17
|
+
specify { expect(described_class).to respond_to(:actions).with(0..1).arguments }
|
18
|
+
|
19
|
+
specify { expect(described_class.actions).to be_a Hash }
|
20
|
+
end # describe
|
21
|
+
|
22
|
+
describe :request do
|
23
|
+
specify { expect(instance).to respond_to(:request).with(0).arguments }
|
24
|
+
specify { expect(instance.request).to be_a [Mithril::Request, nil] }
|
25
|
+
end # describe
|
26
|
+
|
27
|
+
describe :actions do
|
28
|
+
specify { expect(instance).to respond_to(:actions).with(0..1).arguments }
|
29
|
+
specify { expect(instance.actions).to be_a Hash }
|
30
|
+
end # describe
|
31
|
+
|
32
|
+
describe :has_action? do
|
33
|
+
let :command do FactoryGirl.generate :action_key; end
|
34
|
+
|
35
|
+
specify { expect(instance).to respond_to(:has_action?).with(1..2).arguments }
|
36
|
+
specify { expect(instance.has_action? command).to be false }
|
37
|
+
specify { expect(instance.has_action? command, true).to be false }
|
38
|
+
end # describe
|
39
|
+
|
40
|
+
describe :invoke_action do
|
41
|
+
specify { expect(instance).to respond_to(:invoke_action).with(2..3).arguments }
|
42
|
+
end # describe
|
43
|
+
|
44
|
+
context "with an action defined" do
|
45
|
+
let :command do FactoryGirl.generate :action_key; end
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
described_class.define_action command do |session, arguments| arguments.join(" "); end
|
49
|
+
end # before each
|
50
|
+
|
51
|
+
specify { expect(described_class.actions).to have_key command }
|
52
|
+
specify { expect(described_class.actions true).to have_key command }
|
53
|
+
|
54
|
+
specify { expect(instance.actions).to have_key command }
|
55
|
+
specify { expect(instance.actions true).to have_key command }
|
56
|
+
|
57
|
+
specify { expect(instance).to have_action command }
|
58
|
+
specify { expect(instance).to have_action command, true }
|
59
|
+
|
60
|
+
describe :invoke_action do
|
61
|
+
let :request do defined?(super) ? super() : FactoryGirl.build(:request); end
|
62
|
+
let :arguments do %w(some args); end
|
63
|
+
let :output do arguments.join(" "); end
|
64
|
+
|
65
|
+
before :each do instance.stub :request do request; end; end
|
66
|
+
|
67
|
+
specify "calls the defined method" do
|
68
|
+
instance.should_receive(:"action_#{command}").with(request.session, arguments)
|
69
|
+
instance.invoke_action command, arguments
|
70
|
+
end # specify
|
71
|
+
|
72
|
+
specify "calls the defined method as private" do
|
73
|
+
instance.should_receive(:"action_#{command}").with(request.session, arguments)
|
74
|
+
instance.invoke_action command, arguments, true
|
75
|
+
end # specify
|
76
|
+
|
77
|
+
specify { instance.invoke_action(command, arguments).should eq output }
|
78
|
+
specify { instance.invoke_action(command, arguments, true).should eq output }
|
79
|
+
end # describe
|
80
|
+
end # context
|
81
|
+
|
82
|
+
describe "with a private action defined" do
|
83
|
+
let :command do FactoryGirl.generate :action_key; end
|
84
|
+
|
85
|
+
before :each do
|
86
|
+
described_class.define_action command, :private => true do |session, arguments|
|
87
|
+
arguments.join(" ")
|
88
|
+
end # define action
|
89
|
+
end # before each
|
90
|
+
|
91
|
+
specify { expect(described_class.actions).not_to have_key command }
|
92
|
+
specify { expect(described_class.actions true).to have_key command }
|
93
|
+
|
94
|
+
specify { expect(instance.actions).not_to have_key command }
|
95
|
+
specify { expect(instance.actions true).to have_key command }
|
96
|
+
|
97
|
+
specify { expect(instance).not_to have_action command }
|
98
|
+
specify { expect(instance).to have_action command, true }
|
99
|
+
|
100
|
+
describe :invoke_action do
|
101
|
+
let :request do defined?(super) ? super() : FactoryGirl.build(:request); end
|
102
|
+
let :arguments do %w(some args); end
|
103
|
+
let :output do arguments.join(" "); end
|
104
|
+
|
105
|
+
before :each do instance.stub :request do request; end; end
|
106
|
+
|
107
|
+
specify "calls the defined method" do
|
108
|
+
instance.should_not_receive(:"action_#{command}")
|
109
|
+
instance.invoke_action command, arguments
|
110
|
+
end # specify
|
111
|
+
|
112
|
+
specify "calls the defined method as private" do
|
113
|
+
instance.should_receive(:"action_#{command}").with(request.session, arguments)
|
114
|
+
instance.invoke_action command, arguments, true
|
115
|
+
end # specify
|
116
|
+
|
117
|
+
specify { instance.invoke_action(command, arguments).should be nil }
|
118
|
+
specify { instance.invoke_action(command, arguments, true).should eq output }
|
119
|
+
end # describe
|
120
|
+
end # describe
|
121
|
+
end # shared_examples
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# spec/mithril/controllers/mixins/help_actions_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/controllers/mixins/actions_base_helper'
|
4
|
+
|
5
|
+
require 'mithril/controllers/mixins/help_actions'
|
6
|
+
|
7
|
+
shared_examples_for Mithril::Controllers::Mixins::HelpActions do
|
8
|
+
it_behaves_like Mithril::Controllers::Mixins::ActionsBase
|
9
|
+
|
10
|
+
describe :help_message do
|
11
|
+
specify { expect(instance).to respond_to(:help_message).with(0).arguments }
|
12
|
+
specify { expect(instance.help_message).to be_a String }
|
13
|
+
end # describe
|
14
|
+
|
15
|
+
describe "help action" do
|
16
|
+
specify { expect(instance).to have_action :help }
|
17
|
+
|
18
|
+
context "with a help string defined" do
|
19
|
+
let :arguments do %w(); end
|
20
|
+
|
21
|
+
before :each do
|
22
|
+
instance.stub :help_message do
|
23
|
+
"You put your left foot in, you take your left foot out."
|
24
|
+
end # stub
|
25
|
+
end # before each
|
26
|
+
|
27
|
+
specify { expect(instance.invoke_action :help, arguments).
|
28
|
+
to match /put your left foot in/i }
|
29
|
+
|
30
|
+
specify { expect(instance.invoke_action :help, arguments).
|
31
|
+
to match /following commands are available/i }
|
32
|
+
end # context
|
33
|
+
|
34
|
+
describe "with no arguments" do
|
35
|
+
let :arguments do %w(); end
|
36
|
+
|
37
|
+
specify { expect(instance.invoke_action :help, arguments).
|
38
|
+
to match /following commands are available/i }
|
39
|
+
specify { expect(instance.invoke_action :help, arguments).
|
40
|
+
to match /help/i }
|
41
|
+
end # context
|
42
|
+
|
43
|
+
describe "with help" do
|
44
|
+
let :arguments do %w(help); end
|
45
|
+
|
46
|
+
specify { expect(instance.invoke_action :help, arguments).
|
47
|
+
to match /the help command/i }
|
48
|
+
end # describe
|
49
|
+
end # describe
|
50
|
+
|
51
|
+
context "with additional actions defined" do
|
52
|
+
let :action_keys do
|
53
|
+
[].tap do |ary|
|
54
|
+
1.times do ary << FactoryGirl.generate(:action_key); end
|
55
|
+
end # tap
|
56
|
+
end # let
|
57
|
+
|
58
|
+
before :each do
|
59
|
+
action_keys.each do |key|
|
60
|
+
described_class.send :define_action, key do |session, arguments|; end
|
61
|
+
end # each
|
62
|
+
end # before each
|
63
|
+
|
64
|
+
describe "help action" do
|
65
|
+
specify "lists available commands" do
|
66
|
+
(action_keys << :help).each do |key|
|
67
|
+
command = key.to_s.gsub('_',' ')
|
68
|
+
expect(instance.invoke_action :help, %w()).to match /#{command}/
|
69
|
+
end # each
|
70
|
+
end # specify
|
71
|
+
|
72
|
+
specify "invokes the command with help" do
|
73
|
+
session = instance.request ? (instance.request.session || {}) : {}
|
74
|
+
action_keys.each do |key|
|
75
|
+
command = key.to_s.gsub('_',' ')
|
76
|
+
instance.should_receive(:"action_#{key}").with(session, %w(help))
|
77
|
+
instance.invoke_action :help, command.split(' ')
|
78
|
+
end # each
|
79
|
+
end # specify
|
80
|
+
end # describe
|
81
|
+
end # context
|
82
|
+
|
83
|
+
context "with additional commands defined" do
|
84
|
+
let :commands do
|
85
|
+
[].tap do |ary|
|
86
|
+
1.times do ary << FactoryGirl.generate(:action_key).to_s.gsub('_', ' '); end
|
87
|
+
end # tap
|
88
|
+
end # let
|
89
|
+
|
90
|
+
before :each do
|
91
|
+
instance.stub :commands do commands; end
|
92
|
+
instance.stub :has_command? do |command| commands.include? command; end
|
93
|
+
end # before each
|
94
|
+
|
95
|
+
describe "help action" do
|
96
|
+
specify "lists available commands" do
|
97
|
+
(commands << "help").each do |command|
|
98
|
+
expect(instance.invoke_action :help, %w()).to match /#{command}/
|
99
|
+
end # each
|
100
|
+
end # specify
|
101
|
+
|
102
|
+
specify "invokes the command with help" do
|
103
|
+
session = instance.request ? (instance.request.session || {}) : {}
|
104
|
+
commands.each do |command|
|
105
|
+
instance.should_receive(:invoke_command).with("#{command} help")
|
106
|
+
instance.invoke_action :help, [command]
|
107
|
+
end # each
|
108
|
+
end # specify
|
109
|
+
end # describe
|
110
|
+
end # context
|
111
|
+
end # shared examples
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# spec/mithril/controllers/proxy_controller_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/controllers/abstract_controller_helper'
|
4
|
+
|
5
|
+
require 'mithril/controllers/abstract_controller'
|
6
|
+
require 'mithril/controllers/proxy_controller'
|
7
|
+
|
8
|
+
shared_examples_for Mithril::Controllers::ProxyController do
|
9
|
+
it_behaves_like Mithril::Controllers::AbstractController
|
10
|
+
|
11
|
+
let :proxy do described_class; end
|
12
|
+
let :child do Class.new Mithril::Controllers::AbstractController; end
|
13
|
+
let :proxy_instance do proxy.new request; end
|
14
|
+
let :child_instance do child.new request; end
|
15
|
+
let :proxy_action do FactoryGirl.generate :action_key; end
|
16
|
+
let :child_action do FactoryGirl.generate :action_key; end
|
17
|
+
let :proxy_command do proxy_action.to_s.gsub('_', ' '); end
|
18
|
+
let :child_command do child_action.to_s.gsub('_', ' '); end
|
19
|
+
|
20
|
+
before :each do
|
21
|
+
proxy.define_action proxy_action do |session, arguments|; "proxy command"; end
|
22
|
+
child.define_action child_action do |session, arguments|; "child command"; end
|
23
|
+
end # before each
|
24
|
+
|
25
|
+
let :session do {}; end
|
26
|
+
let :arguments do []; end
|
27
|
+
|
28
|
+
specify { expect(proxy_instance).to have_action proxy_action }
|
29
|
+
specify { expect(child_instance).to have_action child_action }
|
30
|
+
specify { expect(proxy_instance).not_to have_action child_action }
|
31
|
+
|
32
|
+
describe :allow_own_actions_while_proxied? do
|
33
|
+
specify { expect(proxy_instance).to respond_to(:allow_own_actions_while_proxied?).
|
34
|
+
with(0).arguments }
|
35
|
+
end # describe
|
36
|
+
|
37
|
+
describe :proxy do
|
38
|
+
specify { expect(proxy_instance).to respond_to(:proxy).with(0).arguments }
|
39
|
+
specify { expect(proxy_instance.proxy).to be_a [Mithril::Controllers::AbstractController, nil] }
|
40
|
+
end # describe proxy
|
41
|
+
|
42
|
+
describe :commands do
|
43
|
+
specify { expect(proxy_instance.commands).to include proxy_command }
|
44
|
+
specify { expect(proxy_instance.commands).not_to include child_command }
|
45
|
+
end # describe
|
46
|
+
|
47
|
+
describe :has_command? do
|
48
|
+
specify { expect(proxy_instance).to have_command proxy_command }
|
49
|
+
specify { expect(proxy_instance).not_to have_command child_command }
|
50
|
+
end # describe
|
51
|
+
|
52
|
+
describe :can_invoke? do
|
53
|
+
specify { expect(proxy_instance.can_invoke? proxy_command).to be true }
|
54
|
+
specify { expect(proxy_instance.can_invoke? child_command).to be false }
|
55
|
+
end # describe
|
56
|
+
|
57
|
+
describe :can_invoke_on_self? do
|
58
|
+
specify { expect(proxy_instance).to respond_to(:can_invoke_on_self?).
|
59
|
+
with(1).arguments }
|
60
|
+
specify { expect(proxy_instance.can_invoke_on_self? proxy_command).to be true }
|
61
|
+
specify { expect(proxy_instance.can_invoke_on_self? child_command).to be false }
|
62
|
+
end # describe
|
63
|
+
|
64
|
+
describe :invoke_command do
|
65
|
+
specify { expect(proxy_instance.invoke_command proxy_command).to eq "proxy command" }
|
66
|
+
end # describe
|
67
|
+
|
68
|
+
context "with a proxy subject defined" do
|
69
|
+
before :each do proxy_instance.stub :proxy do child_instance; end; end
|
70
|
+
|
71
|
+
specify { expect(proxy_instance.proxy).to be child_instance }
|
72
|
+
|
73
|
+
specify { expect(proxy_instance.commands).to include child_command }
|
74
|
+
|
75
|
+
specify { expect(proxy_instance).to have_command child_command }
|
76
|
+
|
77
|
+
specify { expect(proxy_instance.can_invoke? child_command).to be true }
|
78
|
+
|
79
|
+
specify { expect(proxy_instance.can_invoke_on_self? child_command).to be false }
|
80
|
+
|
81
|
+
specify { expect(proxy_instance.invoke_command child_command).to eq "child command" }
|
82
|
+
|
83
|
+
context "allowing own actions" do
|
84
|
+
before :each do proxy_instance.stub :allow_own_actions_while_proxied? do true; end; end
|
85
|
+
|
86
|
+
specify { expect(proxy_instance.allow_own_actions_while_proxied?).to be true }
|
87
|
+
|
88
|
+
specify { expect(proxy_instance.commands).to include proxy_command }
|
89
|
+
|
90
|
+
specify { expect(proxy_instance).to have_command proxy_command }
|
91
|
+
|
92
|
+
specify { expect(proxy_instance.can_invoke? proxy_command).to be true }
|
93
|
+
|
94
|
+
specify { expect(proxy_instance.invoke_command proxy_command).to eq "proxy command" }
|
95
|
+
end # context
|
96
|
+
|
97
|
+
context "allowing own actions" do
|
98
|
+
before :each do proxy_instance.stub :allow_own_actions_while_proxied? do false; end; end
|
99
|
+
|
100
|
+
specify { expect(proxy_instance.allow_own_actions_while_proxied?).to be false }
|
101
|
+
|
102
|
+
specify { expect(proxy_instance.commands).not_to include proxy_command }
|
103
|
+
|
104
|
+
specify { expect(proxy_instance).not_to have_command proxy_command }
|
105
|
+
|
106
|
+
specify { expect(proxy_instance.can_invoke? proxy_command).to be false }
|
107
|
+
|
108
|
+
specify { expect(proxy_instance.invoke_command proxy_command).to match /don't know how/i }
|
109
|
+
end # context
|
110
|
+
end # context
|
111
|
+
end # shared examples
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# spec/mithril/mixin_helper.rb
|
2
|
+
|
3
|
+
require 'mithril/mixin'
|
4
|
+
|
5
|
+
shared_examples_for Mithril::Mixin do
|
6
|
+
let :ancestor_instance_method do FactoryGirl.generate(:action_key); end
|
7
|
+
let :ancestor_class_method do FactoryGirl.generate(:action_key); end
|
8
|
+
let :ancestor_module do
|
9
|
+
mod = Module.new
|
10
|
+
mod.send :extend, Mithril::Mixin
|
11
|
+
mod.send :define_method, ancestor_instance_method do; end
|
12
|
+
mod.const_set :ClassMethods, Module.new
|
13
|
+
mod::ClassMethods.send :define_method, ancestor_class_method do; end
|
14
|
+
mod
|
15
|
+
end # let
|
16
|
+
|
17
|
+
let :parent_instance_method do FactoryGirl.generate(:action_key); end
|
18
|
+
let :parent_class_method do FactoryGirl.generate(:action_key); end
|
19
|
+
let :parent_module do
|
20
|
+
mod = Module.new
|
21
|
+
mod.send :extend, Mithril::Mixin
|
22
|
+
mod.send :mixin, ancestor_module
|
23
|
+
mod.send :define_method, parent_instance_method do; end
|
24
|
+
mod.const_set :ClassMethods, Module.new
|
25
|
+
mod::ClassMethods.send :define_method, parent_class_method do; end
|
26
|
+
mod
|
27
|
+
end # let
|
28
|
+
|
29
|
+
context "with a direct mixin" do
|
30
|
+
before :each do described_class.send :mixin, ancestor_module; end
|
31
|
+
|
32
|
+
describe "instance methods are mixed in" do
|
33
|
+
specify { expect(instance).to respond_to ancestor_instance_method }
|
34
|
+
end # describe
|
35
|
+
|
36
|
+
describe "class method are mixed in" do
|
37
|
+
specify { expect(described_class).to respond_to ancestor_class_method }
|
38
|
+
end # describe
|
39
|
+
end # context
|
40
|
+
|
41
|
+
context "with a cascading mixin" do
|
42
|
+
before :each do described_class.send :mixin, parent_module; end
|
43
|
+
|
44
|
+
describe "instance methods are mixed in" do
|
45
|
+
specify { expect(instance).to respond_to ancestor_instance_method }
|
46
|
+
specify { expect(instance).to respond_to parent_instance_method }
|
47
|
+
end # describe
|
48
|
+
|
49
|
+
describe "class method are mixed in" do
|
50
|
+
specify { expect(described_class).to respond_to ancestor_class_method }
|
51
|
+
specify { expect(described_class).to respond_to parent_class_method }
|
52
|
+
end # describe
|
53
|
+
end # context
|
54
|
+
end # shared examples
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# spec/spec_helper.rb
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'factory_girl'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.color_enabled = true
|
8
|
+
end # config
|
9
|
+
|
10
|
+
#=# Require Factories, Custom Matchers, &c #=#
|
11
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mithril-specs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rob "Merlin" Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mithril
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: factory_girl
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.2'
|
62
|
+
description: Spec helpers for the Mithril interactive text engine
|
63
|
+
email: merlin@sleepingkingstudios.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- spec/mithril/controllers/_text_controller_helper.rb
|
69
|
+
- spec/mithril/controllers/abstract_controller_helper.rb
|
70
|
+
- spec/mithril/controllers/mixins/actions_base_helper.rb
|
71
|
+
- spec/mithril/controllers/mixins/help_actions_helper.rb
|
72
|
+
- spec/mithril/controllers/proxy_controller_helper.rb
|
73
|
+
- spec/mithril/mixin_helper.rb
|
74
|
+
- spec/mithril/spec_helper.rb
|
75
|
+
- CHANGELOG.md
|
76
|
+
- README.md
|
77
|
+
homepage: http://sleepingkingstudios.com
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- spec
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.24
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Mithril spec helpers
|
101
|
+
test_files: []
|