dchelimsky-rspec-stories 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.
- data/History.txt +5 -0
- data/License.txt +22 -0
- data/Manifest.txt +78 -0
- data/README.txt +23 -0
- data/Rakefile +87 -0
- data/init.rb +4 -0
- data/lib/spec/runner/formatter/story/html_formatter.rb +174 -0
- data/lib/spec/runner/formatter/story/plain_text_formatter.rb +194 -0
- data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +42 -0
- data/lib/spec/runner/options_extensions.rb +25 -0
- data/lib/spec/stories.rb +11 -0
- data/lib/spec/story/extensions.rb +3 -0
- data/lib/spec/story/extensions/main.rb +86 -0
- data/lib/spec/story/extensions/regexp.rb +9 -0
- data/lib/spec/story/extensions/string.rb +9 -0
- data/lib/spec/story/given_scenario.rb +14 -0
- data/lib/spec/story/runner.rb +57 -0
- data/lib/spec/story/runner/plain_text_story_runner.rb +48 -0
- data/lib/spec/story/runner/scenario_collector.rb +18 -0
- data/lib/spec/story/runner/scenario_runner.rb +54 -0
- data/lib/spec/story/runner/story_mediator.rb +137 -0
- data/lib/spec/story/runner/story_parser.rb +247 -0
- data/lib/spec/story/runner/story_runner.rb +74 -0
- data/lib/spec/story/scenario.rb +14 -0
- data/lib/spec/story/step.rb +70 -0
- data/lib/spec/story/step_group.rb +89 -0
- data/lib/spec/story/step_mother.rb +38 -0
- data/lib/spec/story/story.rb +39 -0
- data/lib/spec/story/version.rb +15 -0
- data/lib/spec/story/world.rb +124 -0
- data/resources/rake/verify_rcov.rake +7 -0
- data/rspec-stories.gemspec +35 -0
- data/spec/spec.opts +6 -0
- data/spec/spec/runner/formatter/story/html_formatter_spec.rb +135 -0
- data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +600 -0
- data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +82 -0
- data/spec/spec/runner/most_recent_spec.rb +0 -0
- data/spec/spec/runner/options_extensions_spec.rb +31 -0
- data/spec/spec/runner/resources/a_bar.rb +0 -0
- data/spec/spec/runner/resources/a_foo.rb +0 -0
- data/spec/spec/runner/resources/a_spec.rb +1 -0
- data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
- data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
- data/spec/spec/runner_spec.rb +11 -0
- data/spec/spec/spec_classes.rb +133 -0
- data/spec/spec/story/builders.rb +46 -0
- data/spec/spec/story/extensions/main_spec.rb +161 -0
- data/spec/spec/story/extensions_spec.rb +14 -0
- data/spec/spec/story/given_scenario_spec.rb +27 -0
- data/spec/spec/story/runner/plain_text_story_runner_spec.rb +90 -0
- data/spec/spec/story/runner/scenario_collector_spec.rb +27 -0
- data/spec/spec/story/runner/scenario_runner_spec.rb +214 -0
- data/spec/spec/story/runner/story_mediator_spec.rb +143 -0
- data/spec/spec/story/runner/story_parser_spec.rb +401 -0
- data/spec/spec/story/runner/story_runner_spec.rb +294 -0
- data/spec/spec/story/runner_spec.rb +93 -0
- data/spec/spec/story/scenario_spec.rb +18 -0
- data/spec/spec/story/step_group_spec.rb +157 -0
- data/spec/spec/story/step_mother_spec.rb +84 -0
- data/spec/spec/story/step_spec.rb +272 -0
- data/spec/spec/story/story_helper.rb +2 -0
- data/spec/spec/story/story_spec.rb +84 -0
- data/spec/spec/story/world_spec.rb +423 -0
- data/spec/spec_helper.rb +84 -0
- data/story_server/prototype/javascripts/builder.js +136 -0
- data/story_server/prototype/javascripts/controls.js +972 -0
- data/story_server/prototype/javascripts/dragdrop.js +976 -0
- data/story_server/prototype/javascripts/effects.js +1117 -0
- data/story_server/prototype/javascripts/prototype.js +4140 -0
- data/story_server/prototype/javascripts/rspec.js +149 -0
- data/story_server/prototype/javascripts/scriptaculous.js +58 -0
- data/story_server/prototype/javascripts/slider.js +276 -0
- data/story_server/prototype/javascripts/sound.js +55 -0
- data/story_server/prototype/javascripts/unittest.js +568 -0
- data/story_server/prototype/lib/server.rb +24 -0
- data/story_server/prototype/stories.html +176 -0
- data/story_server/prototype/stylesheets/rspec.css +136 -0
- data/story_server/prototype/stylesheets/test.css +90 -0
- metadata +154 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/story_helper'
|
2
|
+
require 'spec/runner/formatter/story/plain_text_formatter'
|
3
|
+
require 'spec/runner/formatter/story/html_formatter'
|
4
|
+
|
5
|
+
module Spec
|
6
|
+
module Story
|
7
|
+
describe Runner, "module" do
|
8
|
+
before(:each) do
|
9
|
+
@world_creator = World.dup
|
10
|
+
@runner_module = Runner.dup
|
11
|
+
@runner_module.instance_eval {@story_runner = nil}
|
12
|
+
@runner_module.stub!(:register_exit_hook)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_options(args=[])
|
16
|
+
Spec::Runner::OptionParser.parse(args, StringIO.new, StringIO.new)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should wire up a singleton StoryRunner' do
|
20
|
+
@runner_module.story_runner.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set its options based on ARGV' do
|
24
|
+
# given
|
25
|
+
@runner_module.should_receive(:run_options).and_return(
|
26
|
+
create_options(['--dry-run'])
|
27
|
+
)
|
28
|
+
|
29
|
+
# when
|
30
|
+
options = @runner_module.run_options
|
31
|
+
|
32
|
+
# then
|
33
|
+
options.dry_run.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "initialization" do
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
# given
|
40
|
+
@story_runner = mock('story runner', :null_object => true)
|
41
|
+
@scenario_runner = mock('scenario runner', :null_object => true)
|
42
|
+
@world_creator = mock('world', :null_object => true)
|
43
|
+
|
44
|
+
@runner_module.stub!(:world_creator).and_return(@world_creator)
|
45
|
+
@runner_module.stub!(:create_story_runner).and_return(@story_runner)
|
46
|
+
@runner_module.stub!(:scenario_runner).and_return(@scenario_runner)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should add a reporter to the runner classes' do
|
50
|
+
@runner_module.should_receive(:run_options).and_return(
|
51
|
+
create_options
|
52
|
+
)
|
53
|
+
|
54
|
+
# expect
|
55
|
+
@world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
|
56
|
+
@story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
|
57
|
+
@scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
|
58
|
+
|
59
|
+
# when
|
60
|
+
@runner_module.story_runner
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should add a documenter to the runner classes if one is specified' do
|
64
|
+
|
65
|
+
@runner_module.should_receive(:run_options).and_return(
|
66
|
+
create_options(["--format","html"])
|
67
|
+
)
|
68
|
+
|
69
|
+
# expect
|
70
|
+
@world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
|
71
|
+
@story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
|
72
|
+
@scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
|
73
|
+
|
74
|
+
# when
|
75
|
+
@runner_module.story_runner
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should add any registered listener to the runner classes' do
|
79
|
+
# given
|
80
|
+
listener = Object.new
|
81
|
+
|
82
|
+
# expect
|
83
|
+
@world_creator.should_receive(:add_listener).with(listener)
|
84
|
+
@story_runner.should_receive(:add_listener).with(listener)
|
85
|
+
@scenario_runner.should_receive(:add_listener).with(listener)
|
86
|
+
|
87
|
+
# when
|
88
|
+
@runner_module.register_listener listener
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/story_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Story
|
5
|
+
describe Scenario do
|
6
|
+
it 'should not raise an error if no body is supplied' do
|
7
|
+
# given
|
8
|
+
story = StoryBuilder.new.to_story
|
9
|
+
|
10
|
+
# when
|
11
|
+
error = exception_from { Scenario.new story, 'name' }
|
12
|
+
|
13
|
+
# then
|
14
|
+
error.should be_nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/story_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Story
|
5
|
+
describe StepGroup do
|
6
|
+
before(:each) do
|
7
|
+
@step_group = StepGroup.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should not find a matcher if empty" do
|
11
|
+
@step_group.find(:given, "this and that").should be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create a given_scenario matcher" do
|
15
|
+
step = @step_group.given_scenario("this and that") {}
|
16
|
+
@step_group.find(:given_scenario, "this and that").should_not be_nil
|
17
|
+
@step_group.find(:given_scenario, "this and that").should equal(step)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should create a given matcher" do
|
21
|
+
step = @step_group.given("this and that") {}
|
22
|
+
@step_group.find(:given, "this and that").should equal(step)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should create a when matcher" do
|
26
|
+
step = @step_group.when("this and that") {}
|
27
|
+
@step_group.find(:when, "this and that").should equal(step)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create a them matcher" do
|
31
|
+
step = @step_group.then("this and that") {}
|
32
|
+
@step_group.find(:then, "this and that").should equal(step)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should add a matcher object" do
|
36
|
+
step = Step.new("this and that") {}
|
37
|
+
@step_group.add(:given, step)
|
38
|
+
@step_group.find(:given, "this and that").should equal(step)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should add it matchers to another StepGroup (with one given)" do
|
42
|
+
source = StepGroup.new
|
43
|
+
target = StepGroup.new
|
44
|
+
step = source.given("this and that") {}
|
45
|
+
source.add_to target
|
46
|
+
target.find(:given, "this and that").should equal(step)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should add it matchers to another StepGroup (with some of each type)" do
|
50
|
+
source = StepGroup.new
|
51
|
+
target = StepGroup.new
|
52
|
+
given_scenario = source.given_scenario("1") {}
|
53
|
+
given = source.given("1") {}
|
54
|
+
when1 = source.when("1") {}
|
55
|
+
when2 = source.when("2") {}
|
56
|
+
then1 = source.then("1") {}
|
57
|
+
then2 = source.then("2") {}
|
58
|
+
then3 = source.then("3") {}
|
59
|
+
source.add_to target
|
60
|
+
target.find(:given_scenario, "1").should equal(given_scenario)
|
61
|
+
target.find(:given, "1").should equal(given)
|
62
|
+
target.find(:when, "1").should equal(when1)
|
63
|
+
target.find(:when, "2").should equal(when2)
|
64
|
+
target.find(:then, "1").should equal(then1)
|
65
|
+
target.find(:then, "2").should equal(then2)
|
66
|
+
target.find(:then, "3").should equal(then3)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should append another collection" do
|
70
|
+
matchers_to_append = StepGroup.new
|
71
|
+
step = matchers_to_append.given("this and that") {}
|
72
|
+
@step_group << matchers_to_append
|
73
|
+
@step_group.find(:given, "this and that").should equal(step)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should append several other collections" do
|
77
|
+
matchers_to_append = StepGroup.new
|
78
|
+
more_matchers_to_append = StepGroup.new
|
79
|
+
first_matcher = matchers_to_append.given("this and that") {}
|
80
|
+
second_matcher = more_matchers_to_append.given("and the other") {}
|
81
|
+
@step_group << matchers_to_append
|
82
|
+
@step_group << more_matchers_to_append
|
83
|
+
@step_group.find(:given, "this and that").should equal(first_matcher)
|
84
|
+
@step_group.find(:given, "and the other").should equal(second_matcher)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should yield itself on initialization" do
|
88
|
+
begin
|
89
|
+
$step_group_spec_step = nil
|
90
|
+
matchers = StepGroup.new do |matchers|
|
91
|
+
$step_group_spec_step = matchers.given("foo") {}
|
92
|
+
end
|
93
|
+
$step_group_spec_step.matches?("foo").should be_true
|
94
|
+
ensure
|
95
|
+
$step_group_spec_step = nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should support defaults" do
|
100
|
+
class StepGroupSubclass < StepGroup
|
101
|
+
steps do |add|
|
102
|
+
add.given("foo") {}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
StepGroupSubclass.new.find(:given, "foo").should_not be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should create a Given" do
|
109
|
+
sub = Class.new(StepGroup).new
|
110
|
+
step = sub.Given("foo") {}
|
111
|
+
sub.find(:given, "foo").should == step
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should create a When" do
|
115
|
+
sub = Class.new(StepGroup).new
|
116
|
+
step = sub.When("foo") {}
|
117
|
+
sub.find(:when, "foo").should == step
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should create a Then" do
|
121
|
+
sub = Class.new(StepGroup).new
|
122
|
+
step = sub.Then("foo") {}
|
123
|
+
sub.find(:then, "foo").should == step
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should create steps in a block" do
|
127
|
+
sub = Class.new(StepGroup).new do
|
128
|
+
Given("a given") {}
|
129
|
+
When("a when") {}
|
130
|
+
Then("a then") {}
|
131
|
+
end
|
132
|
+
sub.find(:given, "a given").should_not be_nil
|
133
|
+
sub.find(:when, "a when").should_not be_nil
|
134
|
+
sub.find(:then, "a then").should_not be_nil
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should clear itself" do
|
138
|
+
step = @step_group.given("this and that") {}
|
139
|
+
@step_group.clear
|
140
|
+
@step_group.find(:given, "this and that").should be_nil
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should tell you when it is empty" do
|
144
|
+
@step_group.should be_empty
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should tell you when it is not empty" do
|
148
|
+
@step_group.given("this and that") {}
|
149
|
+
@step_group.should_not be_empty
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should handle << nil" do
|
153
|
+
@step_group << nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/story_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Story
|
5
|
+
describe StepMother do
|
6
|
+
it 'should store a step by name and type' do
|
7
|
+
# given
|
8
|
+
step_mother = StepMother.new
|
9
|
+
step = Step.new("a given", &lambda {})
|
10
|
+
step_mother.store(:given, step)
|
11
|
+
|
12
|
+
# when
|
13
|
+
found = step_mother.find(:given, "a given")
|
14
|
+
|
15
|
+
# then
|
16
|
+
found.should == step
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should NOT raise an error if a step is missing' do
|
20
|
+
# given
|
21
|
+
step_mother = StepMother.new
|
22
|
+
|
23
|
+
# then
|
24
|
+
lambda do
|
25
|
+
# when
|
26
|
+
step_mother.find(:given, "doesn't exist")
|
27
|
+
end.should_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create a default step which raises a pending error" do
|
31
|
+
# given
|
32
|
+
step_mother = StepMother.new
|
33
|
+
|
34
|
+
# when
|
35
|
+
step = step_mother.find(:given, "doesn't exist")
|
36
|
+
|
37
|
+
# then
|
38
|
+
step.should be_an_instance_of(Step)
|
39
|
+
|
40
|
+
lambda do
|
41
|
+
step.perform(Object.new, "doesn't exist")
|
42
|
+
end.should raise_error(Spec::Example::ExamplePendingError, /Unimplemented/)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should create a default step with it's name stripped" do
|
46
|
+
# given
|
47
|
+
step_mother = StepMother.new
|
48
|
+
|
49
|
+
# when
|
50
|
+
step = step_mother.find(:given, "doesn't exist\n\n")
|
51
|
+
|
52
|
+
# then
|
53
|
+
step.should be_an_instance_of(Step)
|
54
|
+
step.name.should == "doesn't exist"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should clear itself' do
|
58
|
+
# given
|
59
|
+
step_mother = StepMother.new
|
60
|
+
step = Step.new("a given") do end
|
61
|
+
step_mother.store(:given, step)
|
62
|
+
|
63
|
+
# when
|
64
|
+
step_mother.clear
|
65
|
+
|
66
|
+
# then
|
67
|
+
step_mother.should be_empty
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should use assigned steps" do
|
71
|
+
step_mother = StepMother.new
|
72
|
+
|
73
|
+
step = Step.new('step') {}
|
74
|
+
step_group = StepGroup.new
|
75
|
+
step_group.add(:given, step)
|
76
|
+
|
77
|
+
step_mother.use(step_group)
|
78
|
+
|
79
|
+
step_mother.find(:given, "step").should equal(step)
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/story_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Story
|
5
|
+
describe Step, "#matching" do
|
6
|
+
it "should match a text string" do
|
7
|
+
step = Step.new("this text") {}
|
8
|
+
step.matches?("this text").should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should match a text string that has additional line returns" do
|
12
|
+
step = Step.new("this text") {}
|
13
|
+
step.matches?("this text\n\n").should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not match a text string that does not start the same" do
|
17
|
+
step = Step.new("this text") {}
|
18
|
+
step.matches?("Xthis text").should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not match a text string that does not end the same" do
|
22
|
+
step = Step.new("this text") {}
|
23
|
+
step.matches?("this textX").should be_false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should match a text string with a param" do
|
27
|
+
step = Step.new("this $param text") {}
|
28
|
+
step.matches?("this anything text").should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not be greedy" do
|
32
|
+
step = Step.new("enter $value for $key") {}
|
33
|
+
step.parse_args("enter 3 for keys for a piano").should == ['3','keys for a piano']
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should match a text string with 3 params" do
|
37
|
+
step = Step.new("1 $one 2 $two 3 $three 4") {}
|
38
|
+
step.matches?("1 a 2 b 3 c 4").should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should match a text string with two params sharing a prefix" do
|
42
|
+
step = Step.new("I am cool $n times out of $n_total")
|
43
|
+
step.matches?("I am cool 3 times out of 7").should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should match a text string with a param at the beginning" do
|
47
|
+
step = Step.new("$one 2 3") {}
|
48
|
+
step.matches?("a 2 3").should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should match a text string with a param at the end" do
|
52
|
+
step = Step.new("1 2 $three") {}
|
53
|
+
step.matches?("1 2 c").should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should match a text string with a dollar sign ($)" do
|
57
|
+
step = Step.new("show me the $$money") {}
|
58
|
+
step.matches?("show me the $kwan").should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should match a string with an escaped dollar sign" do
|
62
|
+
step = Step.new("show me the \$money") {}
|
63
|
+
step.matches?("show me the $kwan").should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not match a different string" do
|
67
|
+
step = Step.new("this text") {}
|
68
|
+
step.matches?("other text").should be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should match a regexp" do
|
72
|
+
step = Step.new(/this text/) {}
|
73
|
+
step.matches?("this text").should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should match a regexp with a match group" do
|
77
|
+
step = Step.new(/this (.*) text/) {}
|
78
|
+
step.matches?("this anything text").should be_true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should match a regexp with a named variable" do
|
82
|
+
step = Step.new(/this $variable text/) {}
|
83
|
+
step.matches?("this anything text").should be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should not match a non matching regexp" do
|
87
|
+
step = Step.new(/this (.*) text/) {}
|
88
|
+
step.matches?("other anything text").should be_false
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should not match a non matching regexp with a named variable" do
|
92
|
+
step = Step.new(/this $variable text/) {}
|
93
|
+
step.matches?("other anything text").should be_false
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should not get bogged down by parens in strings" do
|
97
|
+
step = Step.new("before () after") {}
|
98
|
+
step.matches?("before () after").should be_true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not get bogged down by regular expression special characters in strings" do
|
102
|
+
step = Step.new("These characters should work ? ( ) [ ] { } ^ !") {}
|
103
|
+
step.matches?("These characters should work ? ( ) [ ] { } ^ !").should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should match any option of an alteration" do
|
107
|
+
step = Step.new(/(he|she) is cool/) {}
|
108
|
+
step.matches?("he is cool").should be_true
|
109
|
+
step.matches?("she is cool").should be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should match alteration as well as a variable" do
|
113
|
+
step = Step.new(/(he|she) is (.*)/) {}
|
114
|
+
step.matches?("he is cool").should be_true
|
115
|
+
step.parse_args("he is cool").should == ['he', 'cool']
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should match alteration as well as a named variable" do
|
119
|
+
step = Step.new(/(he|she) is $adjective/) {}
|
120
|
+
step.matches?("he is cool").should be_true
|
121
|
+
step.parse_args("he is cool").should == ['he', 'cool']
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should match alteration as well as a anonymous and named variable" do
|
125
|
+
step = Step.new(/(he|she) is (.*?) $adjective/) {}
|
126
|
+
step.matches?("he is very cool").should be_true
|
127
|
+
step.parse_args("he is very cool").should == ['he', 'very', 'cool']
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should match a regex with a dollar sign ($)" do
|
131
|
+
step = Step.new(/show me the \$\d+/) {}
|
132
|
+
step.matches?("show me the $123").should be_true
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should match a regex with a dollar sign and named variable" do
|
136
|
+
step = Step.new(/show me the \$$money/) {}
|
137
|
+
step.matches?("show me the $123").should be_true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should match a multiline regex" do
|
141
|
+
step = Step.new(/.*should have text.$text/) {}
|
142
|
+
step.matches?(<<TEXT).should be_true
|
143
|
+
should have text
|
144
|
+
this is the text
|
145
|
+
and so is this
|
146
|
+
TEXT
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should match the beginning of the string, not the line" do
|
150
|
+
step = Step.new(/should have text/) {}
|
151
|
+
step.matches?(<<TEXT).should be_false
|
152
|
+
whatever
|
153
|
+
should have text
|
154
|
+
TEXT
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should match the end of the string, not the line" do
|
158
|
+
step = Step.new(/should have text/) {}
|
159
|
+
step.matches?(<<TEXT).should be_false
|
160
|
+
should have text
|
161
|
+
whatever
|
162
|
+
TEXT
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe Step, "#parse_args" do
|
167
|
+
it "should return an empty array for a text string with no parameters" do
|
168
|
+
step = Step.new("this text") {}
|
169
|
+
step.parse_args("this text").should == []
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should return an empty array for a text string with additional line returns and no parameters" do
|
173
|
+
step = Step.new("this text") {}
|
174
|
+
step.parse_args("this text\n\n").should == []
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe Step do
|
179
|
+
it "should be pending with no block" do
|
180
|
+
step = Step.new("foo")
|
181
|
+
lambda {
|
182
|
+
step.perform(Object.new)
|
183
|
+
}.should raise_error(Spec::Example::ExamplePendingError, "Not Yet Implemented")
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should perform itself on an object" do
|
187
|
+
# given
|
188
|
+
$instance = nil
|
189
|
+
step = Step.new 'step' do
|
190
|
+
$instance = self
|
191
|
+
end
|
192
|
+
instance = Object.new
|
193
|
+
|
194
|
+
# when
|
195
|
+
step.perform(instance, "step")
|
196
|
+
|
197
|
+
# then
|
198
|
+
$instance.should == instance
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should perform itself with one parameter with match expression" do
|
202
|
+
# given
|
203
|
+
$result = nil
|
204
|
+
step = Step.new 'an account with $count dollars' do |count|
|
205
|
+
$result = count
|
206
|
+
end
|
207
|
+
instance = Object.new
|
208
|
+
|
209
|
+
# when
|
210
|
+
args = step.parse_args("an account with 3 dollars")
|
211
|
+
step.perform(instance, *args)
|
212
|
+
|
213
|
+
# then
|
214
|
+
$result.should == "3"
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should perform itself with one parameter without a match expression" do
|
218
|
+
# given
|
219
|
+
$result = nil
|
220
|
+
step = Step.new 'an account with a balance of' do |amount|
|
221
|
+
$result = amount
|
222
|
+
end
|
223
|
+
instance = Object.new
|
224
|
+
|
225
|
+
# when
|
226
|
+
step.perform(instance, 20)
|
227
|
+
|
228
|
+
# then
|
229
|
+
$result.should == 20
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should perform itself with 2 parameters" do
|
233
|
+
# given
|
234
|
+
$account_type = nil
|
235
|
+
$amount = nil
|
236
|
+
step = Step.new 'a $account_type account with $amount dollars' do |account_type, amount|
|
237
|
+
$account_type = account_type
|
238
|
+
$amount = amount
|
239
|
+
end
|
240
|
+
instance = Object.new
|
241
|
+
|
242
|
+
# when
|
243
|
+
args = step.parse_args("a savings account with 3 dollars")
|
244
|
+
step.perform(instance, *args)
|
245
|
+
|
246
|
+
# then
|
247
|
+
$account_type.should == "savings"
|
248
|
+
$amount.should == "3"
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should perform itself when defined with a regexp with 2 parameters" do
|
252
|
+
# given
|
253
|
+
$pronoun = nil
|
254
|
+
$adjective = nil
|
255
|
+
step = Step.new /(he|she) is (.*)/ do |pronoun, adjective|
|
256
|
+
$pronoun = pronoun
|
257
|
+
$adjective = adjective
|
258
|
+
end
|
259
|
+
instance = Object.new
|
260
|
+
|
261
|
+
# when
|
262
|
+
args = step.parse_args("he is cool")
|
263
|
+
step.perform(instance, *args)
|
264
|
+
|
265
|
+
# then
|
266
|
+
$pronoun.should == "he"
|
267
|
+
$adjective.should == "cool"
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|