rspec-given 2.4.1 → 2.4.2
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.
- checksums.yaml +7 -0
- data/Gemfile +2 -10
- data/Gemfile.lock +12 -64
- data/MIT-LICENSE +1 -2
- data/README.md +16 -3
- data/Rakefile +17 -11
- data/doc/main.rdoc +7 -0
- data/examples/stack/stack_spec.rb +17 -18
- data/lib/rspec/given/evaluator.rb +39 -0
- data/lib/rspec/given/natural_assertion.rb +20 -42
- data/lib/rspec/given/version.rb +1 -1
- data/spec/lib/rspec/given/evaluator_spec.rb +31 -0
- data/spec/lib/rspec/given/ext/numeric_spec.rb +22 -0
- data/spec/lib/rspec/given/ext/numeric_specifications.rb +22 -0
- data/spec/lib/rspec/given/extensions_spec.rb +204 -0
- data/spec/lib/rspec/given/failure_spec.rb +17 -0
- data/spec/lib/rspec/given/file_cache_spec.rb +28 -0
- data/spec/lib/rspec/given/fuzzy_number_spec.rb +111 -0
- data/spec/lib/rspec/given/have_failed_spec.rb +70 -0
- data/spec/lib/rspec/given/lexical_purity_spec.rb +19 -0
- data/spec/lib/rspec/given/line_extractor_spec.rb +86 -0
- data/spec/lib/rspec/given/module_methods_spec.rb +13 -0
- data/spec/lib/rspec/given/natural_assertion_spec.rb +178 -0
- data/spec/lib/rspec/given/options_spec.rb +139 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/faux_then.rb +53 -0
- data/spec/support/natural_assertion_control.rb +15 -0
- metadata +36 -73
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2526965146d0b14ab9961e98cd410bcbc2778294
|
4
|
+
data.tar.gz: 34ec57d90eb5e434f33932b35cc029ca38933822
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a5e34bc27ea98957e2494940ede0550dc77199ccf77bd44d3e9bce24d7561c9ebdbfaeb15994a3a9fb9ff3be01b35194ab947b0011d6cc48051a924adf11d74c
|
7
|
+
data.tar.gz: cfbbcf7d2975f67a2487d08da61c58622688a73f607a97250cb77e548fee7f0c080a38fc19e336af6d2219bd3b725b0ff8a13551b91698ff65d004a8ab6c20ba
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,54 +1,15 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-given (2.4.1)
|
5
|
+
rspec (>= 2.12)
|
6
|
+
sorcerer (>= 0.3.7)
|
7
|
+
|
1
8
|
GEM
|
2
9
|
remote: https://rubygems.org/
|
3
10
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
multi_json (~> 1.0)
|
7
|
-
blankslate (3.1.2)
|
8
|
-
bluecloth (2.2.0)
|
9
|
-
charlock_holmes (0.6.9.1)
|
10
|
-
diff-lcs (1.2.1)
|
11
|
-
escape_utils (0.2.4)
|
12
|
-
ffi (1.0.11)
|
13
|
-
flay (2.1.0)
|
14
|
-
ruby_parser (~> 3.0)
|
15
|
-
sexp_processor (~> 4.0)
|
16
|
-
flog (3.2.2)
|
17
|
-
ruby_parser (~> 3.1, > 3.1.0)
|
18
|
-
sexp_processor (~> 4.0)
|
19
|
-
gemoji (1.4.0)
|
20
|
-
ghpreview (0.0.6)
|
21
|
-
github-linguist (= 2.1)
|
22
|
-
html-pipeline (= 0.0.6)
|
23
|
-
httpclient
|
24
|
-
listen
|
25
|
-
rb-fsevent
|
26
|
-
github-linguist (2.1.0)
|
27
|
-
charlock_holmes (~> 0.6.6)
|
28
|
-
escape_utils (~> 0.2.3)
|
29
|
-
mime-types (~> 1.18)
|
30
|
-
pygments.rb (~> 0.2.13)
|
31
|
-
github-markdown (0.5.3)
|
32
|
-
html-pipeline (0.0.6)
|
33
|
-
activesupport (>= 2)
|
34
|
-
escape_utils (~> 0.2)
|
35
|
-
gemoji (~> 1.0)
|
36
|
-
github-linguist (~> 2.1)
|
37
|
-
github-markdown (~> 0.5)
|
38
|
-
nokogiri (~> 1.4)
|
39
|
-
rinku (~> 1.7)
|
40
|
-
sanitize (~> 2.0)
|
41
|
-
httpclient (2.3.3)
|
42
|
-
i18n (0.6.4)
|
43
|
-
listen (0.7.3)
|
44
|
-
mime-types (1.21)
|
45
|
-
multi_json (1.6.1)
|
46
|
-
nokogiri (1.5.6)
|
47
|
-
pygments.rb (0.2.13)
|
48
|
-
rubypython (~> 0.5.3)
|
49
|
-
rake (10.0.3)
|
50
|
-
rb-fsevent (0.9.3)
|
51
|
-
rinku (1.7.2)
|
11
|
+
diff-lcs (1.2.4)
|
12
|
+
rake (10.0.4)
|
52
13
|
rspec (2.13.0)
|
53
14
|
rspec-core (~> 2.13.0)
|
54
15
|
rspec-expectations (~> 2.13.0)
|
@@ -56,25 +17,12 @@ GEM
|
|
56
17
|
rspec-core (2.13.1)
|
57
18
|
rspec-expectations (2.13.0)
|
58
19
|
diff-lcs (>= 1.1.3, < 2.0)
|
59
|
-
rspec-mocks (2.13.
|
60
|
-
ruby_parser (3.1.1)
|
61
|
-
sexp_processor (~> 4.1)
|
62
|
-
rubypython (0.5.3)
|
63
|
-
blankslate (>= 2.1.2.3)
|
64
|
-
ffi (~> 1.0.7)
|
65
|
-
sanitize (2.0.3)
|
66
|
-
nokogiri (>= 1.4.4, < 1.6)
|
67
|
-
sexp_processor (4.1.5)
|
20
|
+
rspec-mocks (2.13.1)
|
68
21
|
sorcerer (0.3.10)
|
69
22
|
|
70
23
|
PLATFORMS
|
71
24
|
ruby
|
72
25
|
|
73
26
|
DEPENDENCIES
|
74
|
-
|
75
|
-
|
76
|
-
flog
|
77
|
-
ghpreview
|
78
|
-
rake (>= 0.9.2.2)
|
79
|
-
rspec (>= 2.12)
|
80
|
-
sorcerer
|
27
|
+
rake
|
28
|
+
rspec-given!
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2011, 2012, 2013 by Jim Weirich
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -18,4 +18,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
data/README.md
CHANGED
@@ -4,12 +4,11 @@
|
|
4
4
|
| :----: |
|
5
5
|
| [](https://travis-ci.org/jimweirich/rspec-given) |
|
6
6
|
|
7
|
-
Covering rspec-given, version 2.4.
|
7
|
+
Covering rspec-given, version 2.4.2.
|
8
8
|
|
9
9
|
rspec-given is an RSpec extension to allow Given/When/Then notation in
|
10
10
|
RSpec specifications. It is a natural extension of the experimental
|
11
|
-
work done on the Given framework.
|
12
|
-
framework can be trivially implemented on top of RSpec.
|
11
|
+
work done on the Given framework.
|
13
12
|
|
14
13
|
# Why Given/When/Then
|
15
14
|
|
@@ -645,8 +644,22 @@ file:
|
|
645
644
|
# ... even when should/expect are detected
|
646
645
|
```
|
647
646
|
|
647
|
+
# License
|
648
|
+
|
649
|
+
RSpec-Given is available under the MIT License. See the MIT-LICENSE
|
650
|
+
file in the source distribution.
|
651
|
+
|
648
652
|
# History
|
649
653
|
|
654
|
+
* Version 2.4.2
|
655
|
+
|
656
|
+
* Minor adjustment to natural assertion error messages to better
|
657
|
+
handle multi-line values.
|
658
|
+
|
659
|
+
* Remove flog, flay and other development tools from the bundle and
|
660
|
+
gemspec. The Rakefile was updated to suggest installing them if
|
661
|
+
they are not there.
|
662
|
+
|
650
663
|
* Version 2.4.1
|
651
664
|
|
652
665
|
* Fix bug where constants from nested modules were not properly
|
data/Rakefile
CHANGED
@@ -2,18 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'rake/clean'
|
4
4
|
require './lib/rspec/given/version'
|
5
|
+
require './lib/rspec/given/module_methods'
|
5
6
|
|
6
7
|
CLEAN.include("pkg/rspec-given-*").exclude("pkg/*.gem")
|
7
8
|
CLOBBER.include("*.gemspec", "html", "README", "README.old")
|
8
9
|
|
9
10
|
# README Formatting --------------------------------------------------
|
10
11
|
|
11
|
-
begin
|
12
|
-
require 'bluecloth'
|
13
|
-
rescue LoadError => ex
|
14
|
-
puts "WARNING: BlueCloth not available"
|
15
|
-
end
|
16
|
-
|
17
12
|
task :default => :ex2
|
18
13
|
|
19
14
|
def version
|
@@ -69,6 +64,11 @@ end
|
|
69
64
|
EXAMPLES = FileList['examples/**/*_spec.rb'].
|
70
65
|
exclude('examples/failing/*.rb').
|
71
66
|
exclude('examples/integration/failing/*.rb')
|
67
|
+
|
68
|
+
unless RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
|
69
|
+
EXAMPLES.exclude("examples/stack/*.rb")
|
70
|
+
end
|
71
|
+
|
72
72
|
FAILING_EXAMPLES = FileList['examples/failing/**/*_spec.rb']
|
73
73
|
|
74
74
|
desc "Run the examples in RSpec 2"
|
@@ -96,7 +96,7 @@ task :verify_rspec2 do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
task :load_check do
|
99
|
-
SRC_FILES = FileList['lib/rspec/given/*.rb'].exclude(
|
99
|
+
SRC_FILES = FileList['lib/rspec/given/*.rb'].exclude(%r(rspec1))
|
100
100
|
SRC_FILES.each do |fn|
|
101
101
|
sh %{ruby -Ilib -e 'load "#{fn}"'}
|
102
102
|
end
|
@@ -108,7 +108,9 @@ directory 'html'
|
|
108
108
|
|
109
109
|
desc "Display the README file"
|
110
110
|
task :readme => ["README.md"] do
|
111
|
-
|
111
|
+
Bundler.with_clean_env do
|
112
|
+
sh "ghpreview README.md"
|
113
|
+
end
|
112
114
|
end
|
113
115
|
|
114
116
|
desc "Generate an RDoc README"
|
@@ -147,9 +149,13 @@ end
|
|
147
149
|
|
148
150
|
# RDoc ---------------------------------------------------------------
|
149
151
|
begin
|
150
|
-
gem "rdoc"
|
151
152
|
require 'rdoc/task'
|
152
|
-
|
153
|
+
if RDoc::VERSION > "2.4.2"
|
154
|
+
RDOC_ENABLED = true
|
155
|
+
else
|
156
|
+
puts "Version of RDoc is too old, please gem install a later version"
|
157
|
+
RDOC_ENABLED = false
|
158
|
+
end
|
153
159
|
rescue LoadError => ex
|
154
160
|
RDOC_ENABLED = false
|
155
161
|
end
|
@@ -205,7 +211,7 @@ if RDOC_ENABLED
|
|
205
211
|
rdoc.title = "RSpec/Given -- A Given/When/Then extension for RSpec"
|
206
212
|
rdoc.options = [
|
207
213
|
'--line-numbers',
|
208
|
-
'--main' , '
|
214
|
+
'--main' , 'doc/main.rdoc',
|
209
215
|
'--title', 'RSpec::Given - Given/When/Then Extensions for RSpec'
|
210
216
|
]
|
211
217
|
rdoc.options << '-SHN' << '-f' << 'darkfish' if DARKFISH_ENABLED
|
data/doc/main.rdoc
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
= Given/When/Then for RSpec
|
2
|
+
|
3
|
+
rspec-given is an RSpec extension to allow Given/When/Then notation in
|
4
|
+
RSpec specifications. It is a natural extension of the experimental
|
5
|
+
work done on the Given framework.
|
6
|
+
|
7
|
+
For more information see http://github.com/jimweirich/rspec-given
|
@@ -2,25 +2,24 @@ require 'rspec/given'
|
|
2
2
|
require 'example_helper'
|
3
3
|
require 'stack'
|
4
4
|
|
5
|
+
RSpec::Given.use_natural_assertions
|
6
|
+
|
5
7
|
describe Stack do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stack
|
10
|
-
end
|
8
|
+
Given(:stack) { Stack.new }
|
9
|
+
Given(:initial_contents) { [] }
|
10
|
+
Given { initial_contents.each do |item| stack.push(item) end }
|
11
11
|
|
12
|
-
|
13
|
-
Invariant { stack.empty?.should == (stack.depth == 0) }
|
12
|
+
Invariant { stack.empty? == (stack.depth == 0) }
|
14
13
|
|
15
|
-
context "
|
14
|
+
context "with an empty stack" do
|
16
15
|
Given(:initial_contents) { [] }
|
17
|
-
Then { stack.depth
|
16
|
+
Then { stack.depth == 0 }
|
18
17
|
|
19
18
|
context "when pushing" do
|
20
19
|
When { stack.push(:an_item) }
|
21
20
|
|
22
|
-
Then { stack.depth
|
23
|
-
Then { stack.top
|
21
|
+
Then { stack.depth == 1 }
|
22
|
+
Then { stack.top == :an_item }
|
24
23
|
end
|
25
24
|
|
26
25
|
context "when popping" do
|
@@ -35,8 +34,8 @@ describe Stack do
|
|
35
34
|
context "when popping" do
|
36
35
|
When(:pop_result) { stack.pop }
|
37
36
|
|
38
|
-
Then { pop_result
|
39
|
-
Then { stack.depth
|
37
|
+
Then { pop_result == :an_item }
|
38
|
+
Then { stack.depth == 0 }
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
@@ -47,16 +46,16 @@ describe Stack do
|
|
47
46
|
context "when pushing" do
|
48
47
|
When { stack.push(:new_item) }
|
49
48
|
|
50
|
-
Then { stack.top
|
51
|
-
Then { stack.depth
|
49
|
+
Then { stack.top == :new_item }
|
50
|
+
Then { stack.depth == original_depth + 1 }
|
52
51
|
end
|
53
52
|
|
54
53
|
context "when popping" do
|
55
54
|
When(:pop_result) { stack.pop }
|
56
55
|
|
57
|
-
Then { pop_result
|
58
|
-
Then { stack.top
|
59
|
-
Then { stack.depth
|
56
|
+
Then { pop_result == :top_item }
|
57
|
+
Then { stack.top == :second_item }
|
58
|
+
Then { stack.depth == original_depth - 1 }
|
60
59
|
end
|
61
60
|
end
|
62
61
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Given
|
3
|
+
class EvalErr
|
4
|
+
def initialize(str)
|
5
|
+
@string = str
|
6
|
+
end
|
7
|
+
def size
|
8
|
+
inspect.size
|
9
|
+
end
|
10
|
+
def to_s
|
11
|
+
@string
|
12
|
+
end
|
13
|
+
def inspect
|
14
|
+
@string
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Evaluator
|
19
|
+
def initialize(example, block)
|
20
|
+
@example = example
|
21
|
+
@block = block
|
22
|
+
end
|
23
|
+
|
24
|
+
def eval_string(exp_string)
|
25
|
+
eval_in_context(exp_string).inspect
|
26
|
+
rescue StandardError => ex
|
27
|
+
EvalErr.new("#{ex.class}: #{ex.message}")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def eval_in_context(exp_string)
|
33
|
+
exp_proc = "proc { #{exp_string} }"
|
34
|
+
blk = eval(exp_proc, @block.binding)
|
35
|
+
@example.instance_eval(&blk)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'rspec/given/module_methods'
|
3
|
+
require 'rspec/given/evaluator'
|
3
4
|
|
4
5
|
if RSpec::Given::NATURAL_ASSERTIONS_SUPPORTED
|
5
6
|
require 'ripper'
|
@@ -12,29 +13,13 @@ module RSpec
|
|
12
13
|
|
13
14
|
InvalidThenError = Class.new(StandardError)
|
14
15
|
|
15
|
-
class EvalErr
|
16
|
-
def initialize(str)
|
17
|
-
@string = str
|
18
|
-
end
|
19
|
-
def size
|
20
|
-
inspect.size
|
21
|
-
end
|
22
|
-
def to_s
|
23
|
-
@string
|
24
|
-
end
|
25
|
-
def inspect
|
26
|
-
@string
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
16
|
class NaturalAssertion
|
31
17
|
|
32
18
|
def initialize(clause_type, block, example, line_extractor)
|
33
19
|
@clause_type = clause_type
|
34
|
-
@
|
35
|
-
@example = example
|
20
|
+
@evaluator = Evaluator.new(example, block)
|
36
21
|
@line_extractor = line_extractor
|
37
|
-
set_file_and_line
|
22
|
+
set_file_and_line(block)
|
38
23
|
end
|
39
24
|
|
40
25
|
VOID_SEXP = [:void_stmt]
|
@@ -56,10 +41,6 @@ module RSpec
|
|
56
41
|
@output
|
57
42
|
end
|
58
43
|
|
59
|
-
def evaluate(expr_string)
|
60
|
-
eval_in_context(expr_string)
|
61
|
-
end
|
62
|
-
|
63
44
|
private
|
64
45
|
|
65
46
|
def using_should?
|
@@ -96,7 +77,7 @@ module RSpec
|
|
96
77
|
|
97
78
|
def expression_value_pairs
|
98
79
|
assertion_subexpressions.map { |exp|
|
99
|
-
[exp, eval_string(exp)]
|
80
|
+
[exp, @evaluator.eval_string(exp)]
|
100
81
|
}
|
101
82
|
end
|
102
83
|
|
@@ -112,8 +93,8 @@ module RSpec
|
|
112
93
|
@source ||= @line_extractor.line(@code_file, @code_line)
|
113
94
|
end
|
114
95
|
|
115
|
-
def set_file_and_line
|
116
|
-
@code_file, @code_line = eval "[__FILE__, __LINE__]",
|
96
|
+
def set_file_and_line(block)
|
97
|
+
@code_file, @code_line = eval "[__FILE__, __LINE__]", block.binding
|
117
98
|
@code_line = @code_line.to_i
|
118
99
|
end
|
119
100
|
|
@@ -168,20 +149,8 @@ module RSpec
|
|
168
149
|
end
|
169
150
|
|
170
151
|
def eval_sexp(sexp)
|
171
|
-
|
172
|
-
eval_string(
|
173
|
-
end
|
174
|
-
|
175
|
-
def eval_string(exp_string)
|
176
|
-
eval_in_context(exp_string).inspect
|
177
|
-
rescue StandardError => ex
|
178
|
-
EvalErr.new("#{ex.class}: #{ex.message}")
|
179
|
-
end
|
180
|
-
|
181
|
-
def eval_in_context(exp_string)
|
182
|
-
exp_proc = "proc { #{exp_string} }"
|
183
|
-
blk = eval(exp_proc, @block.binding)
|
184
|
-
@example.instance_eval(&blk)
|
152
|
+
expr_string = Sorcerer.source(sexp)
|
153
|
+
@evaluator.eval_string(expr_string)
|
185
154
|
end
|
186
155
|
|
187
156
|
WRAP_WIDTH = 20
|
@@ -189,13 +158,22 @@ module RSpec
|
|
189
158
|
def display_pairs(pairs)
|
190
159
|
width = suggest_width(pairs)
|
191
160
|
pairs.each do |x, v|
|
192
|
-
|
193
|
-
|
194
|
-
|
161
|
+
v = adjust_indentation(v)
|
162
|
+
fmt = multi_line?(v) ?
|
163
|
+
"%-#{width+2}s\n #{' '*(width+2)} <- %s\n" :
|
164
|
+
"%-#{width+2}s <- %s\n"
|
195
165
|
@output << sprintf(fmt, v, x)
|
196
166
|
end
|
197
167
|
end
|
198
168
|
|
169
|
+
def adjust_indentation(string)
|
170
|
+
string.to_s.gsub(/^/, ' ')
|
171
|
+
end
|
172
|
+
|
173
|
+
def multi_line?(string)
|
174
|
+
(string.size > WRAP_WIDTH) || (string =~ /\n/)
|
175
|
+
end
|
176
|
+
|
199
177
|
def suggest_width(pairs)
|
200
178
|
pairs.map { |x,v| v.size }.select { |n| n < WRAP_WIDTH }.max || 10
|
201
179
|
end
|