rspec-core 2.0.0.beta.7 → 2.0.0.beta.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cucumber.yml +1 -1
- data/features/hooks/before_and_after_hooks.feature +42 -16
- data/features/pending/pending_examples.feature +6 -6
- data/features/subject/explicit_subject.feature +2 -3
- data/features/subject/implicit_subject.feature +0 -4
- data/features/support/env.rb +1 -1
- data/lib/rspec/core.rb +2 -0
- data/lib/rspec/core/errors.rb +14 -0
- data/lib/rspec/core/example.rb +57 -64
- data/lib/rspec/core/example_group.rb +61 -66
- data/lib/rspec/core/formatters/base_text_formatter.rb +11 -8
- data/lib/rspec/core/formatters/documentation_formatter.rb +4 -4
- data/lib/rspec/core/pending.rb +19 -0
- data/lib/rspec/core/subject.rb +1 -1
- data/rspec-core.gemspec +14 -12
- data/spec/rspec/core/configuration_spec.rb +3 -3
- data/spec/rspec/core/example_group_spec.rb +70 -128
- data/spec/rspec/core/example_spec.rb +39 -17
- data/spec/rspec/core/formatters/helpers_spec.rb +5 -4
- data/spec/rspec/core/let_spec.rb +42 -0
- data/spec/rspec/core/pending_example_spec.rb +72 -6
- data/spec/rspec/core/shared_example_group_spec.rb +77 -93
- data/spec/rspec/core/subject_spec.rb +6 -6
- data/spec/rspec/core/world_spec.rb +4 -4
- data/spec/spec_helper.rb +14 -7
- metadata +13 -11
- data/spec/rspec/core/mocha_spec.rb +0 -27
@@ -1,44 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rspec::Core::Example, :parent_metadata => 'sample' do
|
4
|
+
let(:example_group) do
|
5
|
+
Rspec::Core::ExampleGroup.describe('group description')
|
6
|
+
end
|
4
7
|
|
5
|
-
|
6
|
-
example_group
|
7
|
-
:metadata => Rspec::Core::Metadata.new.process(
|
8
|
-
'group description',
|
9
|
-
:caller => ['foo_spec.rb:37']
|
10
|
-
)
|
11
|
-
).as_null_object
|
12
|
-
@example = Rspec::Core::Example.new(example_group, 'example description', {}, (lambda {}))
|
8
|
+
let(:example) do
|
9
|
+
example_group.example('example description')
|
13
10
|
end
|
14
11
|
|
15
12
|
describe "attr readers" do
|
16
13
|
it "should have one for the parent example group" do
|
17
|
-
|
14
|
+
example.should respond_to(:example_group)
|
18
15
|
end
|
19
16
|
|
20
17
|
it "should have one for it's description" do
|
21
|
-
|
18
|
+
example.should respond_to(:description)
|
22
19
|
end
|
23
20
|
|
24
21
|
it "should have one for it's metadata" do
|
25
|
-
|
22
|
+
example.should respond_to(:metadata)
|
26
23
|
end
|
27
24
|
|
28
25
|
it "should have one for it's block" do
|
29
|
-
|
26
|
+
example.should respond_to(:example_block)
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
30
|
describe '#inspect' do
|
34
31
|
it "should return 'group description - description'" do
|
35
|
-
|
32
|
+
example.inspect.should == 'group description example description'
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
39
36
|
describe '#to_s' do
|
40
37
|
it "should return #inspect" do
|
41
|
-
|
38
|
+
example.to_s.should == example.inspect
|
42
39
|
end
|
43
40
|
end
|
44
41
|
|
@@ -60,9 +57,34 @@ describe Rspec::Core::Example, :parent_metadata => 'sample' do
|
|
60
57
|
end
|
61
58
|
|
62
59
|
describe "#run" do
|
63
|
-
|
60
|
+
it "runs after(:each) when the example passes" do
|
61
|
+
after_run = false
|
62
|
+
group = Rspec::Core::ExampleGroup.describe do
|
63
|
+
after(:each) { after_run = true }
|
64
|
+
example('example') { 1.should == 1 }
|
65
|
+
end
|
66
|
+
group.run_all
|
67
|
+
after_run.should be_true, "expected after(:each) to be run"
|
68
|
+
end
|
64
69
|
|
65
|
-
|
66
|
-
|
70
|
+
it "runs after(:each) when the example fails" do
|
71
|
+
after_run = false
|
72
|
+
group = Rspec::Core::ExampleGroup.describe do
|
73
|
+
after(:each) { after_run = true }
|
74
|
+
example('example') { 1.should == 2 }
|
75
|
+
end
|
76
|
+
group.run_all
|
77
|
+
after_run.should be_true, "expected after(:each) to be run"
|
78
|
+
end
|
67
79
|
|
80
|
+
it "runs after(:each) when the example raises an Exception" do
|
81
|
+
after_run = false
|
82
|
+
group = Rspec::Core::ExampleGroup.describe do
|
83
|
+
after(:each) { after_run = true }
|
84
|
+
example('example') { raise "this error" }
|
85
|
+
end
|
86
|
+
group.run_all
|
87
|
+
after_run.should be_true, "expected after(:each) to be run"
|
88
|
+
end
|
89
|
+
end
|
68
90
|
end
|
@@ -5,9 +5,10 @@ describe Rspec::Core::Formatters::Helpers do
|
|
5
5
|
let(:helper) { helper = Object.new.extend(Rspec::Core::Formatters::Helpers) }
|
6
6
|
|
7
7
|
describe "format seconds" do
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it "uses passed in precision if specified" do
|
9
|
+
pending("get regex right to handle this case where we don't want it to consume all zeroes") do
|
10
|
+
helper.format_seconds(0.00005, 2).should == "0.00"
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
context "sub second times" do
|
@@ -35,4 +36,4 @@ describe Rspec::Core::Formatters::Helpers do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
|
38
|
-
end
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#let" do
|
4
|
+
let(:counter) do
|
5
|
+
Class.new do
|
6
|
+
def initialize
|
7
|
+
@count = 0
|
8
|
+
end
|
9
|
+
def count
|
10
|
+
@count += 1
|
11
|
+
end
|
12
|
+
end.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it "generates an instance method" do
|
16
|
+
counter.count.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "caches the value" do
|
20
|
+
counter.count.should == 1
|
21
|
+
counter.count.should == 2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#let!" do
|
26
|
+
let!(:creator) do
|
27
|
+
class Creator
|
28
|
+
@count = 0
|
29
|
+
def self.count
|
30
|
+
@count += 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "evaluates the value non-lazily" do
|
36
|
+
lambda { Creator.count }.should_not raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not interfere between tests" do
|
40
|
+
Creator.count.should == 1
|
41
|
+
end
|
42
|
+
end
|
@@ -1,19 +1,85 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
Rspec::Matchers.define :
|
3
|
+
Rspec::Matchers.define :be_pending_with do |message|
|
4
4
|
match do |example|
|
5
|
-
example.metadata[:pending]
|
5
|
+
example.metadata[:pending] && example.metadata[:execution_result][:pending_message] == message
|
6
|
+
end
|
7
|
+
|
8
|
+
failure_message_for_should do |example|
|
9
|
+
"expected example to pending with #{message.inspect}, got #{example.metadata[:execution_result][:pending_message].inspect}"
|
6
10
|
end
|
7
11
|
end
|
8
12
|
|
9
13
|
describe "an example" do
|
10
14
|
context "with no block" do
|
11
|
-
it "is listed as pending" do
|
12
|
-
group = Rspec::Core::ExampleGroup.
|
15
|
+
it "is listed as pending with 'Not Yet Implemented'" do
|
16
|
+
group = Rspec::Core::ExampleGroup.describe('group') do
|
13
17
|
it "has no block"
|
14
18
|
end
|
15
|
-
group.
|
16
|
-
group.
|
19
|
+
example = group.examples.first
|
20
|
+
example.run(group.new, stub.as_null_object)
|
21
|
+
example.should be_pending_with('Not Yet Implemented')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with no args" do
|
26
|
+
it "is listed as pending with 'No reason given'" do
|
27
|
+
group = Rspec::Core::ExampleGroup.describe('group') do
|
28
|
+
it "does something" do
|
29
|
+
pending
|
30
|
+
end
|
31
|
+
end
|
32
|
+
example = group.examples.first
|
33
|
+
example.run(group.new, stub.as_null_object)
|
34
|
+
example.should be_pending_with('No reason given')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a message" do
|
39
|
+
it "is listed as pending with the supplied message" do
|
40
|
+
group = Rspec::Core::ExampleGroup.describe('group') do
|
41
|
+
it "does something" do
|
42
|
+
pending("just because")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
example = group.examples.first
|
46
|
+
example.run(group.new, stub.as_null_object)
|
47
|
+
example.should be_pending_with('just because')
|
17
48
|
end
|
18
49
|
end
|
50
|
+
|
51
|
+
context "with a block" do
|
52
|
+
context "that fails" do
|
53
|
+
it "is listed as pending with the supplied message" do
|
54
|
+
group = Rspec::Core::ExampleGroup.describe('group') do
|
55
|
+
it "does something" do
|
56
|
+
pending("just because") do
|
57
|
+
3.should == 4
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
example = group.examples.first
|
62
|
+
example.run(group.new, stub.as_null_object)
|
63
|
+
example.should be_pending_with('just because')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "that passes" do
|
68
|
+
it "raises a PendingExampleFixedError" do
|
69
|
+
group = Rspec::Core::ExampleGroup.describe('group') do
|
70
|
+
it "does something" do
|
71
|
+
pending("just because") do
|
72
|
+
3.should == 3
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
example = group.examples.first
|
77
|
+
example.run(group.new, stub.as_null_object)
|
78
|
+
example.metadata[:pending].should be_false
|
79
|
+
example.metadata[:execution_result][:status].should == 'failed'
|
80
|
+
example.metadata[:execution_result][:exception_encountered].should be_a(Rspec::Core::PendingExampleFixedError)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
19
85
|
end
|
@@ -17,7 +17,7 @@ module Rspec::Core
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should raise an ArgumentError when adding a second shared example group with the same name" do
|
20
|
-
group = ExampleGroup.
|
20
|
+
group = ExampleGroup.describe('example group')
|
21
21
|
group.share_examples_for('really important business value') { }
|
22
22
|
lambda do
|
23
23
|
group.share_examples_for('really important business value') { }
|
@@ -35,14 +35,8 @@ module Rspec::Core
|
|
35
35
|
|
36
36
|
describe "including shared example_groups using #it_should_behave_like" do
|
37
37
|
|
38
|
-
def cleanup_shared_example_groups
|
39
|
-
original_shared_example_groups = Rspec::Core.world.shared_example_groups
|
40
|
-
yield if block_given?
|
41
|
-
Rspec::Core.world.shared_example_groups.replace(original_shared_example_groups)
|
42
|
-
end
|
43
|
-
|
44
38
|
it "should make any shared example_group available at the correct level", :ruby => 1.8 do
|
45
|
-
group = ExampleGroup.
|
39
|
+
group = ExampleGroup.describe('fake group')
|
46
40
|
block = lambda {
|
47
41
|
def self.class_helper; end
|
48
42
|
def extra_helper; end
|
@@ -54,163 +48,153 @@ module Rspec::Core
|
|
54
48
|
end
|
55
49
|
|
56
50
|
it "should make any shared example_group available at the correct level", :ruby => 1.9 do
|
57
|
-
group = ExampleGroup.
|
58
|
-
|
51
|
+
group = ExampleGroup.describe
|
52
|
+
shared_examples_for(:shared_example_group) do
|
59
53
|
def self.class_helper; end
|
60
54
|
def extra_helper; end
|
61
|
-
|
62
|
-
Rspec::Core.world.stub(:shared_example_groups).and_return({ :shared_example_group => block })
|
55
|
+
end
|
63
56
|
group.it_should_behave_like :shared_example_group
|
64
57
|
group.instance_methods.should include(:extra_helper)
|
65
58
|
group.singleton_methods.should include(:class_helper)
|
66
59
|
end
|
67
60
|
|
68
61
|
it "raises when named shared example_group can not be found" do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end.should raise_error(/Could not find shared example group named/)
|
74
|
-
end
|
62
|
+
group = ExampleGroup.describe("example_group")
|
63
|
+
lambda do
|
64
|
+
group.it_should_behave_like("a group that does not exist")
|
65
|
+
end.should raise_error(/Could not find shared example group named/)
|
75
66
|
end
|
76
67
|
|
77
68
|
it "adds examples to current example_group using it_should_behave_like" do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
69
|
+
group = ExampleGroup.describe("example_group") do
|
70
|
+
it("i was already here") {}
|
71
|
+
end
|
82
72
|
|
83
|
-
|
73
|
+
group.examples.size.should == 1
|
84
74
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
75
|
+
group.share_examples_for('shared example_group') do
|
76
|
+
it("shared example") {}
|
77
|
+
it("shared example 2") {}
|
78
|
+
end
|
89
79
|
|
90
|
-
|
80
|
+
group.it_should_behave_like("shared example_group")
|
91
81
|
|
92
|
-
|
93
|
-
end
|
82
|
+
group.examples.size.should == 3
|
94
83
|
end
|
95
84
|
|
96
85
|
it "adds examples to from two shared groups" do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
86
|
+
group = ExampleGroup.describe("example_group") do
|
87
|
+
it("i was already here") {}
|
88
|
+
end
|
101
89
|
|
102
|
-
|
90
|
+
group.examples.size.should == 1
|
103
91
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
92
|
+
group.share_examples_for('test 2 shared groups') do
|
93
|
+
it("shared example") {}
|
94
|
+
it("shared example 2") {}
|
95
|
+
end
|
108
96
|
|
109
|
-
|
110
|
-
|
111
|
-
|
97
|
+
group.share_examples_for('test 2 shared groups 2') do
|
98
|
+
it("shared example 3") {}
|
99
|
+
end
|
112
100
|
|
113
|
-
|
114
|
-
|
101
|
+
group.it_should_behave_like("test 2 shared groups")
|
102
|
+
group.it_should_behave_like("test 2 shared groups 2")
|
115
103
|
|
116
|
-
|
117
|
-
end
|
104
|
+
group.examples.size.should == 4
|
118
105
|
end
|
119
106
|
|
120
|
-
share_as('Cornucopia') do
|
121
|
-
it "is plentiful" do
|
122
|
-
5.should == 4
|
123
|
-
end
|
124
|
-
end
|
125
107
|
|
126
108
|
it "adds examples to current example_group using include", :compat => 'rspec-1.2' do
|
127
|
-
|
109
|
+
share_as('Cornucopia') do
|
110
|
+
it "is plentiful" do
|
111
|
+
5.should == 4
|
112
|
+
end
|
113
|
+
end
|
114
|
+
group = ExampleGroup.describe('group') { include Cornucopia }
|
128
115
|
group.examples.length.should == 1
|
129
116
|
group.examples.first.metadata[:description].should == "is plentiful"
|
130
117
|
end
|
131
118
|
|
132
119
|
it "adds examples to current example_group using it_should_behave_like with a module" do
|
133
|
-
|
134
|
-
group = ExampleGroup.create("example_group") {}
|
120
|
+
group = ExampleGroup.describe("example_group") {}
|
135
121
|
|
136
|
-
|
137
|
-
|
138
|
-
|
122
|
+
shared_foo = group.share_as(:FooShared) do
|
123
|
+
it("shared example") {}
|
124
|
+
end
|
139
125
|
|
140
|
-
|
126
|
+
group.it_should_behave_like(::FooShared)
|
141
127
|
|
142
|
-
|
143
|
-
end
|
128
|
+
group.examples.size.should == 1
|
144
129
|
end
|
145
130
|
|
146
131
|
describe "running shared examples" do
|
147
132
|
module ::RunningSharedExamplesJustForTesting; end
|
148
133
|
|
149
|
-
|
150
|
-
|
134
|
+
before(:each) do
|
135
|
+
share_examples_for("it runs shared examples") do
|
136
|
+
include ::RunningSharedExamplesJustForTesting
|
137
|
+
|
138
|
+
class << self
|
139
|
+
def magic
|
140
|
+
$magic ||= {}
|
141
|
+
end
|
142
|
+
|
143
|
+
def count(scope)
|
144
|
+
@counters ||= {
|
145
|
+
:before_all => 0,
|
146
|
+
:before_each => 0,
|
147
|
+
:after_each => 0,
|
148
|
+
:after_all => 0
|
149
|
+
}
|
150
|
+
@counters[scope] += 1
|
151
|
+
end
|
152
|
+
end
|
151
153
|
|
152
|
-
class << self
|
153
154
|
def magic
|
154
155
|
$magic ||= {}
|
155
156
|
end
|
156
157
|
|
157
158
|
def count(scope)
|
158
|
-
|
159
|
-
:before_all => 0,
|
160
|
-
:before_each => 0,
|
161
|
-
:after_each => 0,
|
162
|
-
:after_all => 0
|
163
|
-
}
|
164
|
-
@counters[scope] += 1
|
159
|
+
self.class.count(scope)
|
165
160
|
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def magic
|
169
|
-
$magic ||= {}
|
170
|
-
end
|
171
161
|
|
172
|
-
|
173
|
-
|
162
|
+
before(:all) { magic[:before_all] = "before all #{count(:before_all)}" }
|
163
|
+
before(:each) { magic[:before_each] = "before each #{count(:before_each)}" }
|
164
|
+
after(:each) { magic[:after_each] = "after each #{count(:after_each)}" }
|
165
|
+
after(:all) { magic[:after_all] = "after all #{count(:after_all)}" }
|
174
166
|
end
|
175
|
-
|
176
|
-
before(:all) { magic[:before_all] = "before all #{count(:before_all)}" }
|
177
|
-
before(:each) { magic[:before_each] = "before each #{count(:before_each)}" }
|
178
|
-
after(:each) { magic[:after_each] = "after each #{count(:after_each)}" }
|
179
|
-
after(:all) { magic[:after_all] = "after all #{count(:after_all)}" }
|
180
167
|
end
|
181
168
|
|
182
169
|
let(:group) do
|
183
|
-
group = ExampleGroup.
|
170
|
+
group = ExampleGroup.describe("example group") do
|
184
171
|
it_should_behave_like "it runs shared examples"
|
185
172
|
it "has one example" do; end
|
186
173
|
it "has another example" do; end
|
174
|
+
it "includes modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
|
175
|
+
raise "FAIL" unless running_example.example_group.included_modules.include?(RunningSharedExamplesJustForTesting)
|
176
|
+
end
|
187
177
|
end
|
188
178
|
end
|
189
179
|
|
190
|
-
before { group.
|
180
|
+
before { group.run_all }
|
191
181
|
|
192
182
|
it "runs before(:all) only once from shared example_group", :compat => 'rspec-1.2' do
|
193
183
|
group.magic[:before_all].should eq("before all 1")
|
194
184
|
end
|
195
185
|
|
196
186
|
it "runs before(:each) from shared example_group", :compat => 'rspec-1.2' do
|
197
|
-
group.magic[:before_each].should eq("before each
|
187
|
+
group.magic[:before_each].should eq("before each 3")
|
198
188
|
end
|
199
189
|
|
200
190
|
it "runs after(:each) from shared example_group", :compat => 'rspec-1.2' do
|
201
|
-
group.magic[:after_each].should eq("after each
|
191
|
+
group.magic[:after_each].should eq("after each 3")
|
202
192
|
end
|
203
193
|
|
204
|
-
it "runs after(:all) only once from shared example_group", :compat => 'rspec-1.2' do
|
194
|
+
it "runs after(:all) only once from shared example_group", :pending => true, :compat => 'rspec-1.2' do
|
205
195
|
group.magic[:after_all].should eq("after all 1")
|
206
196
|
end
|
207
197
|
|
208
|
-
it_should_behave_like "it runs shared examples"
|
209
|
-
|
210
|
-
it "includes modules, included into shared example_group, into current example_group", :compat => 'rspec-1.2' do
|
211
|
-
running_example.example_group.included_modules.should include(RunningSharedExamplesJustForTesting)
|
212
|
-
end
|
213
|
-
|
214
198
|
it "makes methods defined in the shared example_group available in consuming example_group", :compat => 'rspec-1.2' do
|
215
199
|
group.magic.should be_a(Hash)
|
216
200
|
end
|