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,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../../spec_helper'
|
2
|
+
require 'spec/runner/formatter/story/progress_bar_formatter'
|
3
|
+
|
4
|
+
module Spec
|
5
|
+
module Runner
|
6
|
+
module Formatter
|
7
|
+
module Story
|
8
|
+
describe ProgressBarFormatter do
|
9
|
+
before :each do
|
10
|
+
# given
|
11
|
+
@out = StringIO.new
|
12
|
+
@out.stub!(:tty?).and_return(true)
|
13
|
+
@tweaker = mock('tweaker')
|
14
|
+
@tweaker.stub!(:tweak_backtrace)
|
15
|
+
@options = mock('options')
|
16
|
+
@options.stub!(:colour).and_return(true)
|
17
|
+
@options.stub!(:backtrace_tweaker).and_return(@tweaker)
|
18
|
+
|
19
|
+
@formatter = ProgressBarFormatter.new(@options, @out)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should print some white space before test summary' do
|
23
|
+
#when
|
24
|
+
@formatter.run_started(1)
|
25
|
+
@formatter.run_ended
|
26
|
+
|
27
|
+
#then
|
28
|
+
@out.string.should =~ /^\n{2}/
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should print how long tests took to complete" do
|
32
|
+
#when
|
33
|
+
now = Time.now
|
34
|
+
future = now+1
|
35
|
+
Time.stub!(:now).and_return(now)
|
36
|
+
@formatter.run_started(1)
|
37
|
+
Time.stub!(:now).and_return(future)
|
38
|
+
@formatter.run_ended
|
39
|
+
|
40
|
+
#then
|
41
|
+
@out.string.should include("Finished in %f seconds" % (future-now))
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
it "should push green dot for passing scenario" do
|
46
|
+
#when
|
47
|
+
@formatter.scenario_started('','')
|
48
|
+
@formatter.step_succeeded('', '')
|
49
|
+
@formatter.scenario_ended
|
50
|
+
@formatter.story_ended '', ''
|
51
|
+
|
52
|
+
#then
|
53
|
+
@out.string.should eql("\e[32m.\e[0m")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should push red F for failure scenario" do
|
57
|
+
#when
|
58
|
+
@formatter.scenario_started('','')
|
59
|
+
@formatter.step_failed('', '')
|
60
|
+
@formatter.scenario_failed('', '', '')
|
61
|
+
@formatter.story_ended '', ''
|
62
|
+
|
63
|
+
#then
|
64
|
+
@out.string.should eql("\e[31mF\e[0m")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should push yellow P for pending scenario" do
|
68
|
+
#when
|
69
|
+
@formatter.scenario_started('','')
|
70
|
+
@formatter.step_pending('', '')
|
71
|
+
@formatter.scenario_pending('story', '', '')
|
72
|
+
@formatter.story_ended '', ''
|
73
|
+
|
74
|
+
#then
|
75
|
+
@out.string.should eql("\e[33mP\e[0m")
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
File without changes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/resources/custom_example_group_runner'
|
3
|
+
|
4
|
+
describe Spec::Runner::OptionsExtensions do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@out = StringIO.new
|
8
|
+
@err = StringIO.new
|
9
|
+
@parser = Spec::Runner::OptionParser.new(@err, @out)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(args)
|
13
|
+
@parser.parse(args)
|
14
|
+
@parser.options
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should add a story_formatters method to the options" do
|
18
|
+
parse([]).should respond_to(:story_formatters)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should use html story formatter when format is h" do
|
22
|
+
options = parse(["--format", "h"])
|
23
|
+
options.story_formatters[0].class.should equal(Spec::Runner::Formatter::Story::HtmlFormatter)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should use html story formatter when format is html" do
|
27
|
+
options = parse(["--format", "html"])
|
28
|
+
options.story_formatters[0].class.should equal(Spec::Runner::Formatter::Story::HtmlFormatter)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Empty - used by ../options_spec.rb
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
describe Runner, ".configure" do
|
5
|
+
it "should yield global configuration" do
|
6
|
+
Spec::Runner.configure do |config|
|
7
|
+
config.should equal(Spec::Runner.configuration)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# This file contains various classes used by the specs.
|
2
|
+
module Spec
|
3
|
+
module Expectations
|
4
|
+
class Person
|
5
|
+
attr_reader :name
|
6
|
+
def initialize name
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
def == other
|
10
|
+
return @name == other.name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ClassWithMultiWordPredicate
|
15
|
+
def multi_word_predicate?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Helper
|
21
|
+
class CollectionWithSizeMethod
|
22
|
+
def initialize; @list = []; end
|
23
|
+
def size; @list.size; end
|
24
|
+
def push(item); @list.push(item); end
|
25
|
+
end
|
26
|
+
|
27
|
+
class CollectionWithLengthMethod
|
28
|
+
def initialize; @list = []; end
|
29
|
+
def length; @list.size; end
|
30
|
+
def push(item); @list.push(item); end
|
31
|
+
end
|
32
|
+
|
33
|
+
class CollectionOwner
|
34
|
+
attr_reader :items_in_collection_with_size_method, :items_in_collection_with_length_method
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@items_in_collection_with_size_method = CollectionWithSizeMethod.new
|
38
|
+
@items_in_collection_with_length_method = CollectionWithLengthMethod.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_to_collection_with_size_method(item)
|
42
|
+
@items_in_collection_with_size_method.push(item)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_to_collection_with_length_method(item)
|
46
|
+
@items_in_collection_with_length_method.push(item)
|
47
|
+
end
|
48
|
+
|
49
|
+
def items_for(arg)
|
50
|
+
return [1, 2, 3] if arg == 'a'
|
51
|
+
[1]
|
52
|
+
end
|
53
|
+
|
54
|
+
def items
|
55
|
+
@items_in_collection_with_size_method
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class HandCodedMock
|
60
|
+
include Spec::Matchers
|
61
|
+
def initialize(return_val)
|
62
|
+
@return_val = return_val
|
63
|
+
@funny_called = false
|
64
|
+
end
|
65
|
+
|
66
|
+
def funny?
|
67
|
+
@funny_called = true
|
68
|
+
@return_val
|
69
|
+
end
|
70
|
+
|
71
|
+
def hungry?(a, b, c)
|
72
|
+
a.should equal(1)
|
73
|
+
b.should equal(2)
|
74
|
+
c.should equal(3)
|
75
|
+
@funny_called = true
|
76
|
+
@return_val
|
77
|
+
end
|
78
|
+
|
79
|
+
def exists?
|
80
|
+
@return_val
|
81
|
+
end
|
82
|
+
|
83
|
+
def multi_word_predicate?
|
84
|
+
@return_val
|
85
|
+
end
|
86
|
+
|
87
|
+
def rspec_verify
|
88
|
+
@funny_called.should be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
class ClassWithUnqueriedPredicate
|
92
|
+
attr_accessor :foo
|
93
|
+
def initialize(foo)
|
94
|
+
@foo = foo
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
module Custom
|
102
|
+
require 'spec/runner/formatter/base_text_formatter'
|
103
|
+
class Formatter < Spec::Runner::Formatter::BaseTextFormatter
|
104
|
+
attr_reader :options, :where
|
105
|
+
|
106
|
+
def initialize(options, where)
|
107
|
+
@options = options
|
108
|
+
@where = where
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
class BadFormatter < Spec::Runner::Formatter::BaseTextFormatter
|
113
|
+
attr_reader :where
|
114
|
+
|
115
|
+
def initialize(options, where)
|
116
|
+
bad_method
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Differ
|
121
|
+
attr_reader :options
|
122
|
+
def initialize(options)
|
123
|
+
@options = options
|
124
|
+
end
|
125
|
+
|
126
|
+
def diff_as_object(target, expected)
|
127
|
+
""
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class FakeReporter < Spec::Runner::Reporter
|
133
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Spec
|
2
|
+
module Story
|
3
|
+
class StoryBuilder
|
4
|
+
def initialize
|
5
|
+
@title = 'a story'
|
6
|
+
@narrative = 'narrative'
|
7
|
+
end
|
8
|
+
|
9
|
+
def title(value)
|
10
|
+
@title = value
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def narrative(value)
|
15
|
+
@narrative = value
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_story(&block)
|
20
|
+
block = lambda {} unless block_given?
|
21
|
+
Story.new @title, @narrative, &block
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class ScenarioBuilder
|
26
|
+
def initialize
|
27
|
+
@name = 'a scenario'
|
28
|
+
@story = StoryBuilder.new.to_story
|
29
|
+
end
|
30
|
+
|
31
|
+
def name(value)
|
32
|
+
@name = value
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def story(value)
|
37
|
+
@story = value
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_scenario(&block)
|
42
|
+
Scenario.new @story, @name, &block
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Story
|
5
|
+
module Extensions
|
6
|
+
describe "the main object extended with Main", :shared => true do
|
7
|
+
before(:each) do
|
8
|
+
@main = Class.new do; include Main; end
|
9
|
+
@original_rspec_story_steps, $rspec_story_steps = $rspec_story_steps, nil
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
$rspec_story_steps = @original_rspec_story_steps
|
14
|
+
end
|
15
|
+
|
16
|
+
def have_step(type, name)
|
17
|
+
return simple_matcher(%[step group containing a #{type} named #{name.inspect}]) do |actual|
|
18
|
+
Spec::Story::Step === actual.find(type, name)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Main, "#run_story" do
|
24
|
+
it_should_behave_like "the main object extended with Main"
|
25
|
+
|
26
|
+
it "should create a PlainTextStoryRunner with run_story" do
|
27
|
+
Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(mock("runner", :null_object => true))
|
28
|
+
@main.run_story
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should yield the runner if arity == 1" do
|
32
|
+
File.should_receive(:read).with("some/path").and_return("Story: foo")
|
33
|
+
$main_spec_runner = nil
|
34
|
+
@main.run_story("some/path") do |runner|
|
35
|
+
$main_spec_runner = runner
|
36
|
+
end
|
37
|
+
$main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should run in the runner if arity == 0" do
|
41
|
+
File.should_receive(:read).with("some/path").and_return("Story: foo")
|
42
|
+
$main_spec_runner = nil
|
43
|
+
@main.run_story("some/path") do
|
44
|
+
$main_spec_runner = self
|
45
|
+
end
|
46
|
+
$main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should tell the PlainTextStoryRunner to run with run_story" do
|
50
|
+
runner = mock("runner")
|
51
|
+
Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(runner)
|
52
|
+
runner.should_receive(:run)
|
53
|
+
@main.run_story
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Main, "#steps_for" do
|
58
|
+
it_should_behave_like "the main object extended with Main"
|
59
|
+
|
60
|
+
it "should have no steps for a non existent key" do
|
61
|
+
@main.steps_for(:key).find(:given, "foo").should be_nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create steps for a key" do
|
65
|
+
$main_spec_invoked = false
|
66
|
+
@main.steps_for(:key) do
|
67
|
+
Given("foo") {
|
68
|
+
$main_spec_invoked = true
|
69
|
+
}
|
70
|
+
end
|
71
|
+
@main.steps_for(:key).find(:given, "foo").perform(Object.new, "foo")
|
72
|
+
$main_spec_invoked.should be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should append steps to steps_for a given key" do
|
76
|
+
@main.steps_for(:key) do
|
77
|
+
Given("first") {}
|
78
|
+
end
|
79
|
+
@main.steps_for(:key) do
|
80
|
+
Given("second") {}
|
81
|
+
end
|
82
|
+
@main.steps_for(:key).should have_step(:given, "first")
|
83
|
+
@main.steps_for(:key).should have_step(:given, "second")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Main, "#with_steps_for adding new steps" do
|
88
|
+
it_should_behave_like "the main object extended with Main"
|
89
|
+
|
90
|
+
it "should result in a group containing pre-existing steps and newly defined steps" do
|
91
|
+
first_group = @main.steps_for(:key) do
|
92
|
+
Given("first") {}
|
93
|
+
end
|
94
|
+
second_group = @main.with_steps_for(:key) do
|
95
|
+
Given("second") {}
|
96
|
+
end
|
97
|
+
|
98
|
+
second_group.should have_step(:given, "first")
|
99
|
+
second_group.should have_step(:given, "second")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not add its steps to the existing group" do
|
103
|
+
first_group = @main.steps_for(:key) do
|
104
|
+
Given("first") {}
|
105
|
+
end
|
106
|
+
second_group = @main.with_steps_for(:key) do
|
107
|
+
Given("second") {}
|
108
|
+
end
|
109
|
+
|
110
|
+
first_group.should have_step(:given, "first")
|
111
|
+
first_group.should_not have_step(:given, "second")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Main, "#with_steps_for running a story" do
|
116
|
+
it_should_behave_like "the main object extended with Main"
|
117
|
+
|
118
|
+
before(:each) do
|
119
|
+
@runner = mock("runner")
|
120
|
+
@runner_step_group = StepGroup.new
|
121
|
+
@runner.stub!(:steps).and_return(@runner_step_group)
|
122
|
+
@runner.stub!(:run)
|
123
|
+
Spec::Story::Runner::PlainTextStoryRunner.stub!(:new).and_return(@runner)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should create a PlainTextStoryRunner with a path" do
|
127
|
+
Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with('path/to/file',{}).and_return(@runner)
|
128
|
+
@main.with_steps_for(:foo) do
|
129
|
+
run 'path/to/file'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should create a PlainTextStoryRunner with a path and options" do
|
134
|
+
Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with(anything,{:bar => :baz}).and_return(@runner)
|
135
|
+
@main.with_steps_for(:foo) do
|
136
|
+
run 'path/to/file', :bar => :baz
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should pass the group it creates to the runner's steps" do
|
141
|
+
steps = @main.steps_for(:ice_cream) do
|
142
|
+
Given("vanilla") {}
|
143
|
+
end
|
144
|
+
@main.with_steps_for(:ice_cream) do
|
145
|
+
run 'foo'
|
146
|
+
end
|
147
|
+
@runner_step_group.should have_step(:given, "vanilla")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should run a story" do
|
151
|
+
@runner.should_receive(:run)
|
152
|
+
Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(@runner)
|
153
|
+
@main.with_steps_for(:foo) do
|
154
|
+
run 'path/to/file'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|