rspec-given 2.0.0 → 2.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -1
- data/Gemfile.lock +2 -0
- data/README.md +6 -10
- data/examples/integration/also_spec.rb +48 -0
- data/examples/spec_helper.rb +4 -0
- data/examples/stack/stack_spec.rb +2 -2
- data/lib/rspec/given/extensions.rb +23 -0
- data/lib/rspec/given/version.rb +3 -1
- metadata +12 -11
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# rspec-given
|
2
2
|
|
3
|
-
Covering rspec-given, version 2.
|
3
|
+
Covering rspec-given, version 2.1.0.beta.1.
|
4
4
|
|
5
5
|
rspec-given is an RSpec extension to allow Given/When/Then notation in
|
6
6
|
RSpec specifications. It is a natural extension of the experimental
|
@@ -46,7 +46,7 @@ describe Stack do
|
|
46
46
|
When { stack.push(:an_item) }
|
47
47
|
|
48
48
|
Then { stack.depth.should == 1 }
|
49
|
-
|
49
|
+
Also { stack.top.should == :an_item }
|
50
50
|
end
|
51
51
|
|
52
52
|
context "when popping" do
|
@@ -62,7 +62,7 @@ describe Stack do
|
|
62
62
|
When(:pop_result) { stack.pop }
|
63
63
|
|
64
64
|
Then { pop_result.should == :an_item }
|
65
|
-
|
65
|
+
Also { stack.depth.should == 0 }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -241,9 +241,9 @@ in term of <tt>size</tt>. Whenever <tt>size</tt> is 0,
|
|
241
241
|
<tt>empty?</tt> should be false.
|
242
242
|
|
243
243
|
You can conceptually think of an _Invariant_ block as a _Then_ block
|
244
|
-
that automatically gets added to every
|
244
|
+
that automatically gets added to every _Then_ within its scope.
|
245
245
|
|
246
|
-
Invariants nested within a context only apply to the
|
246
|
+
Invariants nested within a context only apply to the _Then_ blocks in
|
247
247
|
that context.
|
248
248
|
|
249
249
|
Invariants that reference a _Given_ precondition accessor must only be
|
@@ -255,11 +255,7 @@ I really like the way the Given framework is working out. I feel my
|
|
255
255
|
tests are much more like specifications when I use it. However, I'm
|
256
256
|
not entirely happy with it.
|
257
257
|
|
258
|
-
|
259
|
-
would essentially be a post-conditions that should be true after
|
260
|
-
_Then_ block in the same (or nested) context as the invariant.
|
261
|
-
|
262
|
-
Second, I would like to remove the need for the ".should" in all the
|
258
|
+
I would like to remove the need for the ".should" in all the
|
263
259
|
_Then_ blocks. In other words, instead of saying:
|
264
260
|
|
265
261
|
Then { x.should == y }
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rspec/given'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Also" do
|
5
|
+
Given(:info) { [] }
|
6
|
+
Given(:mock) { flexmock("mock") }
|
7
|
+
|
8
|
+
describe "Also is called after Then" do
|
9
|
+
Given { mock.should_receive(:also_ran).once }
|
10
|
+
Then { info << "T" }
|
11
|
+
Also {
|
12
|
+
info.should == ["T"]
|
13
|
+
mock.also_ran
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Also is called only once with multiple Thens" do
|
18
|
+
Then { info << "T" }
|
19
|
+
Then { info << "T2" }
|
20
|
+
Also { info.should == ["T"] }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Inherited Alsos are not run" do
|
24
|
+
Then { info << "T-OUTER" }
|
25
|
+
Also { info << "A-OUTER" }
|
26
|
+
Also { info.should == ["T-OUTER", "A-OUTER"] }
|
27
|
+
|
28
|
+
context "inner" do
|
29
|
+
Then { info << "T-INNER" }
|
30
|
+
Also { info << "A-INNER" }
|
31
|
+
Also { info.should == ["T-INNER", "A-INNER"] }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "Alsos require a Then" do
|
36
|
+
begin
|
37
|
+
Also { }
|
38
|
+
rescue StandardError => ex
|
39
|
+
@message = ex.message
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should define a message" do
|
43
|
+
message = self.class.instance_eval { @message }
|
44
|
+
message.should =~ /also.*without.*then/i
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/examples/spec_helper.rb
CHANGED
@@ -20,7 +20,7 @@ describe Stack do
|
|
20
20
|
When { stack.push(:an_item) }
|
21
21
|
|
22
22
|
Then { stack.depth.should == 1 }
|
23
|
-
|
23
|
+
Also { stack.top.should == :an_item }
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when popping" do
|
@@ -36,7 +36,7 @@ describe Stack do
|
|
36
36
|
When(:pop_result) { stack.pop }
|
37
37
|
|
38
38
|
Then { pop_result.should == :an_item }
|
39
|
-
|
39
|
+
Also { stack.depth.should == 0 }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -31,11 +31,20 @@ module RSpec
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def _rg_check_alsos # :nodoc:
|
35
|
+
return if self.class._rg_context_info[:also_ran]
|
36
|
+
self.class._rg_alsos.each do |block|
|
37
|
+
instance_eval(&block)
|
38
|
+
end
|
39
|
+
self.class._rg_context_info[:also_ran] = true
|
40
|
+
end
|
41
|
+
|
34
42
|
# Implement the run-time semantics of the Then clause.
|
35
43
|
def _rg_then(&block) # :nodoc:
|
36
44
|
_rg_establish_givens
|
37
45
|
_rg_check_invariants
|
38
46
|
instance_eval(&block)
|
47
|
+
_rg_check_alsos
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
@@ -53,6 +62,14 @@ module RSpec
|
|
53
62
|
@_rg_invariants ||= []
|
54
63
|
end
|
55
64
|
|
65
|
+
def _rg_alsos
|
66
|
+
@_rg_alsos ||= []
|
67
|
+
end
|
68
|
+
|
69
|
+
def _rg_context_info
|
70
|
+
@_rg_contet_info ||= {}
|
71
|
+
end
|
72
|
+
|
56
73
|
# Trigger the evaluation of a Given! block by referencing its
|
57
74
|
# name.
|
58
75
|
def _rg_trigger_given(name) # :nodoc:
|
@@ -145,6 +162,7 @@ module RSpec
|
|
145
162
|
file = eval "__FILE__", b
|
146
163
|
line = eval "__LINE__", b
|
147
164
|
eval %{specify do _rg_then(&block) end}, binding, file, line
|
165
|
+
_rg_context_info[:then_defined] = true
|
148
166
|
end
|
149
167
|
|
150
168
|
# Establish an invariant that must be true for all Then blocks
|
@@ -152,6 +170,11 @@ module RSpec
|
|
152
170
|
def Invariant(&block)
|
153
171
|
_rg_invariants << block
|
154
172
|
end
|
173
|
+
|
174
|
+
def Also(&block)
|
175
|
+
fail "Also defined without a Then" unless _rg_context_info[:then_defined]
|
176
|
+
_rg_alsos << block
|
177
|
+
end
|
155
178
|
end
|
156
179
|
end
|
157
180
|
end
|
data/lib/rspec/given/version.rb
CHANGED
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-given
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.0.beta.1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jim Weirich
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70227316783380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.2.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70227316783380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bluecloth
|
27
|
-
requirement: &
|
27
|
+
requirement: &70227316782580 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70227316782580
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc
|
38
|
-
requirement: &
|
38
|
+
requirement: &70227316781360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>'
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 2.4.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70227316781360
|
47
47
|
description: ! 'Given is an RSpec extension that allows explicit definition of the
|
48
48
|
|
49
49
|
pre and post-conditions for code under test.
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/rspec/given/rspec1_given.rb
|
68
68
|
- lib/rspec/given/version.rb
|
69
69
|
- lib/rspec/given.rb
|
70
|
+
- examples/integration/also_spec.rb
|
70
71
|
- examples/integration/focused_line_spec.rb
|
71
72
|
- examples/integration/given_spec.rb
|
72
73
|
- examples/integration/invariant_spec.rb
|
@@ -96,9 +97,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
98
|
none: false
|
98
99
|
requirements:
|
99
|
-
- - ! '
|
100
|
+
- - ! '>'
|
100
101
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
102
|
+
version: 1.3.1
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project: given
|
104
105
|
rubygems_version: 1.8.15
|