shoulda-context 1.2.1 → 1.2.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 +4 -4
- data/README.md +28 -15
- data/lib/shoulda/context/context.rb +8 -6
- data/lib/shoulda/context/version.rb +1 -1
- data/shoulda-context.gemspec +3 -0
- data/test/shoulda/context_test.rb +8 -1
- metadata +44 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f5e8f0cc83d3b44bd9eddf2193085c1b9fea968
|
4
|
+
data.tar.gz: 7c8a322dea7cfb60550eb4a199a01346f86bfaa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b441e5a21877364af355eb9a431fbd05be5065cd3c646c3335d397b87a1eb857e71c11a7f9b6884896c18c4dceb83ffcdde80773ed71ae31575b3d2a12c643e2
|
7
|
+
data.tar.gz: 5893017828229249e980f1f4c67c08a04ec3619942a8b9dd455727be8d71525a39927ea764a3f8b3ba3fa90069bc99c77d92694b978329a60c64277ce3036ca8
|
data/README.md
CHANGED
@@ -13,27 +13,40 @@ about using shoulda with Rails or RSpec.
|
|
13
13
|
Instead of writing Ruby methods with `lots_of_underscores`, shoulda-context adds
|
14
14
|
context, setup, and should blocks...
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
```ruby
|
17
|
+
require "test/unit"
|
18
|
+
|
19
|
+
class CalculatorTest < Test::Unit::TestCase
|
20
|
+
context "a calculator" do
|
21
|
+
setup do
|
22
|
+
@calculator = Calculator.new
|
23
|
+
end
|
24
|
+
|
25
|
+
should "add two numbers for the sum" do
|
26
|
+
assert_equal 4, @calculator.sum(2, 2)
|
27
|
+
end
|
28
|
+
|
29
|
+
should "multiply two numbers for the product" do
|
30
|
+
assert_equal 10, @calculator.product(2, 5)
|
30
31
|
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
```
|
31
35
|
|
32
36
|
... which combine to produce the following test methods:
|
33
37
|
|
34
38
|
"test: a calculator should add two numbers for the sum."
|
35
39
|
"test: a calculator should multiply two numbers for the product."
|
36
40
|
|
41
|
+
When running a single test method via (example from a Rails context):
|
42
|
+
|
43
|
+
ruby -I"lib:test" path_to_test_file -n name_of_the_test_method
|
44
|
+
|
45
|
+
you should include a trailing space(!), e.g.,
|
46
|
+
|
47
|
+
ruby -I"lib:test" path_to_test_file -n "test: a calculator should add two numbers for the sum. "
|
48
|
+
|
49
|
+
|
37
50
|
## Assertions
|
38
51
|
|
39
52
|
It also has two additional Test::Unit assertions for working with Ruby's Array:
|
@@ -50,5 +63,5 @@ Thank you to all the [contributors](https://github.com/thoughtbot/shoulda-contex
|
|
50
63
|
|
51
64
|
## License
|
52
65
|
|
53
|
-
Shoulda is Copyright © 2006-
|
66
|
+
Shoulda is Copyright © 2006-2016 thoughtbot, inc.
|
54
67
|
It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
@@ -210,7 +210,9 @@ module Shoulda
|
|
210
210
|
@described_type ||= self.name.
|
211
211
|
gsub(/Test$/, '').
|
212
212
|
split('::').
|
213
|
-
inject(Object)
|
213
|
+
inject(Object) do |parent, local_name|
|
214
|
+
parent.const_get(local_name, false)
|
215
|
+
end
|
214
216
|
end
|
215
217
|
|
216
218
|
# Sets the return value of the subject instance method:
|
@@ -394,9 +396,10 @@ module Shoulda
|
|
394
396
|
end
|
395
397
|
|
396
398
|
test_methods[test_unit_class][test_name.to_s] = true
|
397
|
-
|
399
|
+
file, line_no = should[:block].source_location
|
398
400
|
context = self
|
399
|
-
test_unit_class.
|
401
|
+
test_unit_class.class_eval <<-end_eval, file, line_no
|
402
|
+
define_method test_name do
|
400
403
|
@shoulda_context = context
|
401
404
|
begin
|
402
405
|
context.run_parent_setup_blocks(self)
|
@@ -404,7 +407,6 @@ module Shoulda
|
|
404
407
|
if self.respond_to?(:instance_exec)
|
405
408
|
self.instance_exec(&should[:before])
|
406
409
|
else
|
407
|
-
# deprecated in Rails 4.x
|
408
410
|
should[:before].bind(self).call
|
409
411
|
end
|
410
412
|
end
|
@@ -412,13 +414,13 @@ module Shoulda
|
|
412
414
|
if self.respond_to?(:instance_exec)
|
413
415
|
self.instance_exec(&should[:block])
|
414
416
|
else
|
415
|
-
# deprecated in Rails 4.x
|
416
417
|
should[:block].bind(self).call
|
417
418
|
end
|
418
419
|
ensure
|
419
420
|
context.run_all_teardown_blocks(self)
|
420
421
|
end
|
421
|
-
|
422
|
+
end
|
423
|
+
end_eval
|
422
424
|
end
|
423
425
|
|
424
426
|
def run_all_setup_blocks(binding)
|
data/shoulda-context.gemspec
CHANGED
@@ -24,4 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency("mocha", "~> 0.9.10")
|
25
25
|
s.add_development_dependency("rake")
|
26
26
|
s.add_development_dependency("test-unit", "~> 2.1.0")
|
27
|
+
s.add_development_dependency("pry")
|
28
|
+
s.add_development_dependency("byebug")
|
29
|
+
s.add_development_dependency("pry-byebug")
|
27
30
|
end
|
@@ -172,13 +172,20 @@ class ::Some
|
|
172
172
|
class NestedModel; end
|
173
173
|
end
|
174
174
|
|
175
|
-
|
176
175
|
class Some::NestedModelTest < Test::Unit::TestCase
|
177
176
|
should "determine the described type for a nested model" do
|
178
177
|
assert_equal Some::NestedModel, self.class.described_type
|
179
178
|
end
|
180
179
|
end
|
181
180
|
|
181
|
+
class Some::SomeTest < Test::Unit::TestCase
|
182
|
+
should "not fallback to higher-level constants with same name" do
|
183
|
+
assert_raises(NameError) do
|
184
|
+
assert_equal nil, self.class.described_type
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
182
189
|
class ShouldMatcherTest < Test::Unit::TestCase
|
183
190
|
class FakeMatcher
|
184
191
|
attr_reader :subject
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoulda-context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoughtbot, inc.
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: appraisal
|
@@ -85,6 +85,48 @@ dependencies:
|
|
85
85
|
- - ~>
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: 2.1.0
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: pry
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: byebug
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
type: :development
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: pry-byebug
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
type: :development
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
88
130
|
description: Context framework extracted from Shoulda
|
89
131
|
email: support@thoughtbot.com
|
90
132
|
executables:
|