shoulda-context 1.2.2 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.rubocop.yml +190 -0
- data/.ruby-version +1 -1
- data/.travis.yml +27 -2
- data/Appraisals +15 -32
- data/CHANGELOG.md +27 -0
- data/Gemfile +4 -1
- data/Gemfile.lock +72 -0
- data/MIT-LICENSE +1 -1
- data/README.md +140 -29
- data/Rakefile +19 -14
- data/bin/install_gems_in_all_appraisals +16 -0
- data/bin/run_all_tests +16 -0
- data/bin/setup +190 -0
- data/bin/supported_ruby_versions +7 -0
- data/bin/update_gem_in_all_appraisals +17 -0
- data/bin/update_gems_in_all_appraisals +16 -0
- data/{bin → exe}/convert_to_should_syntax +0 -0
- data/gemfiles/rails_4_2.gemfile +10 -0
- data/gemfiles/rails_4_2.gemfile.lock +164 -0
- data/gemfiles/rails_5_0.gemfile +10 -0
- data/gemfiles/rails_5_0.gemfile.lock +170 -0
- data/gemfiles/rails_5_1.gemfile +10 -0
- data/gemfiles/rails_5_1.gemfile.lock +170 -0
- data/gemfiles/rails_5_2.gemfile +10 -0
- data/gemfiles/rails_5_2.gemfile.lock +178 -0
- data/lib/shoulda/context.rb +12 -16
- data/lib/shoulda/context/assertions.rb +16 -13
- data/lib/shoulda/context/configuration.rb +19 -0
- data/lib/shoulda/context/context.rb +22 -305
- data/lib/shoulda/context/dsl.rb +279 -0
- data/lib/shoulda/context/railtie.rb +14 -0
- data/lib/shoulda/context/test_framework_detection.rb +4 -5
- data/lib/shoulda/context/version.rb +1 -1
- data/lib/shoulda/context/world.rb +22 -0
- data/shoulda-context.gemspec +19 -17
- data/test/fake_rails_root/test/shoulda_macros/custom_macro.rb +1 -1
- data/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +1 -2
- data/test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +1 -2
- data/test/shoulda/autoload_macro_test.rb +1 -1
- data/test/shoulda/context_test.rb +92 -53
- data/test/shoulda/convert_to_should_syntax_test.rb +5 -7
- data/test/shoulda/helpers_test.rb +24 -59
- data/test/shoulda/railtie_test.rb +43 -0
- data/test/shoulda/should_test.rb +163 -24
- data/test/shoulda/test_framework_detection_test.rb +64 -71
- data/test/support/current_bundle.rb +61 -0
- data/test/support/rails_application_with_shoulda_context.rb +46 -0
- data/test/support/snowglobe.rb +5 -0
- data/test/test_helper.rb +35 -11
- metadata +71 -60
- data/gemfiles/minitest_4_x.gemfile +0 -7
- data/gemfiles/minitest_4_x.gemfile.lock +0 -96
- data/gemfiles/minitest_5_x.gemfile +0 -7
- data/gemfiles/minitest_5_x.gemfile.lock +0 -102
- data/gemfiles/rails_3_0.gemfile +0 -8
- data/gemfiles/rails_3_0.gemfile.lock +0 -93
- data/gemfiles/rails_3_1.gemfile +0 -10
- data/gemfiles/rails_3_1.gemfile.lock +0 -114
- data/gemfiles/rails_3_2.gemfile +0 -10
- data/gemfiles/rails_3_2.gemfile.lock +0 -112
- data/gemfiles/rails_4_0.gemfile +0 -10
- data/gemfiles/rails_4_0.gemfile.lock +0 -107
- data/gemfiles/rails_4_1.gemfile +0 -10
- data/gemfiles/rails_4_1.gemfile.lock +0 -119
- data/gemfiles/test_unit.gemfile +0 -7
- data/gemfiles/test_unit.gemfile.lock +0 -95
- data/init.rb +0 -1
- data/rails/init.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51bde035855288943372f8d9fc71310416ae02ddacbab30f912e5abbce21ab5f
|
4
|
+
data.tar.gz: ce5ee8ece26119b829ab2851b3607ed1f62c00478115ede3e3a987dc86455e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef854338d26cb4613673c019d38fd66411899e5ab983421ed3d0db45449ac527c982faa8910b831421fd1a1edfbfa6f1e8572bba6d191ba17809b6b8aef4a338
|
7
|
+
data.tar.gz: e2854aad28db7d53de92728d00df9b51395e142d3f74a41da75883e8febc2a2e062c48d84e96879b9bae88f49bbce9002fd29442da33068e7d44d8042eea2e75
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
Exclude:
|
4
|
+
- '*.gemspec'
|
5
|
+
Layout/AlignParameters:
|
6
|
+
EnforcedStyle: with_fixed_indentation
|
7
|
+
Layout/ConditionPosition:
|
8
|
+
Enabled: false
|
9
|
+
Layout/DotPosition:
|
10
|
+
EnforcedStyle: trailing
|
11
|
+
Layout/MultilineMethodCallIndentation:
|
12
|
+
EnforcedStyle: indented
|
13
|
+
Lint/AmbiguousOperator:
|
14
|
+
Enabled: false
|
15
|
+
Lint/AmbiguousRegexpLiteral:
|
16
|
+
Enabled: false
|
17
|
+
Lint/AssignmentInCondition:
|
18
|
+
Enabled: false
|
19
|
+
Lint/DeprecatedClassMethods:
|
20
|
+
Enabled: false
|
21
|
+
Lint/ElseLayout:
|
22
|
+
Enabled: false
|
23
|
+
Lint/HandleExceptions:
|
24
|
+
Enabled: false
|
25
|
+
Lint/IndentHeredoc:
|
26
|
+
Enabled: false
|
27
|
+
Lint/LiteralInInterpolation:
|
28
|
+
Enabled: false
|
29
|
+
Lint/Loop:
|
30
|
+
Enabled: false
|
31
|
+
Lint/ParenthesesAsGroupedExpression:
|
32
|
+
Enabled: false
|
33
|
+
Lint/RequireParentheses:
|
34
|
+
Enabled: false
|
35
|
+
Lint/UnderscorePrefixedVariableName:
|
36
|
+
Enabled: false
|
37
|
+
Lint/Void:
|
38
|
+
Enabled: false
|
39
|
+
Metrics/BlockLength:
|
40
|
+
Enabled: false
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Enabled: false
|
43
|
+
Metrics/LineLength:
|
44
|
+
IgnoredPatterns:
|
45
|
+
- "^[ ]*describe.+$"
|
46
|
+
- "^[ ]*context.+$"
|
47
|
+
- "^[ ]*shared_context.+$"
|
48
|
+
- "^[ ]*shared_examples_for.+$"
|
49
|
+
- "^[ ]*it.+$"
|
50
|
+
- "^[ ]*'.+?' => '.+?',?$"
|
51
|
+
- "^[ ]*\".+?\" => \".+?\",?$"
|
52
|
+
- "^[ ]*.+?: .+?$"
|
53
|
+
Metrics/MethodLength:
|
54
|
+
Max: 30
|
55
|
+
Naming/AccessorMethodName:
|
56
|
+
Enabled: false
|
57
|
+
Naming/AsciiIdentifiers:
|
58
|
+
Enabled: false
|
59
|
+
Naming/BinaryOperatorParameterName:
|
60
|
+
Enabled: false
|
61
|
+
Naming/MemoizedInstanceVariableName:
|
62
|
+
EnforcedStyleForLeadingUnderscores: required
|
63
|
+
Style/ClassVars:
|
64
|
+
Enabled: false
|
65
|
+
Style/ColonMethodCall:
|
66
|
+
Enabled: false
|
67
|
+
Naming/FileName:
|
68
|
+
Enabled: false
|
69
|
+
Rails:
|
70
|
+
Enabled: true
|
71
|
+
Rails/Delegate:
|
72
|
+
Enabled: false
|
73
|
+
Rails/HttpPositionalArguments:
|
74
|
+
Enabled: false
|
75
|
+
Style/Alias:
|
76
|
+
Enabled: false
|
77
|
+
Style/ArrayJoin:
|
78
|
+
Enabled: false
|
79
|
+
Style/AsciiComments:
|
80
|
+
Enabled: false
|
81
|
+
Style/Attr:
|
82
|
+
Enabled: false
|
83
|
+
Style/CaseEquality:
|
84
|
+
Enabled: false
|
85
|
+
Style/CharacterLiteral:
|
86
|
+
Enabled: false
|
87
|
+
Style/ClassAndModuleChildren:
|
88
|
+
Enabled: false
|
89
|
+
Style/CollectionMethods:
|
90
|
+
PreferredMethods:
|
91
|
+
find: detect
|
92
|
+
reduce: inject
|
93
|
+
collect: map
|
94
|
+
find_all: select
|
95
|
+
Style/CommentAnnotation:
|
96
|
+
Enabled: false
|
97
|
+
Style/Documentation:
|
98
|
+
Enabled: false
|
99
|
+
Style/DoubleNegation:
|
100
|
+
Enabled: false
|
101
|
+
Style/EachWithObject:
|
102
|
+
Enabled: false
|
103
|
+
Style/EmptyLiteral:
|
104
|
+
Enabled: false
|
105
|
+
Style/Encoding:
|
106
|
+
Enabled: false
|
107
|
+
Style/EvenOdd:
|
108
|
+
Enabled: false
|
109
|
+
Style/ExpandPathArguments:
|
110
|
+
Enabled: false
|
111
|
+
Style/FlipFlop:
|
112
|
+
Enabled: false
|
113
|
+
Style/FormatString:
|
114
|
+
Enabled: false
|
115
|
+
Style/FrozenStringLiteralComment:
|
116
|
+
Enabled: false
|
117
|
+
Style/GlobalVars:
|
118
|
+
Enabled: false
|
119
|
+
Style/GuardClause:
|
120
|
+
Enabled: false
|
121
|
+
Style/IfUnlessModifier:
|
122
|
+
Enabled: false
|
123
|
+
Style/IfWithSemicolon:
|
124
|
+
Enabled: false
|
125
|
+
Style/InlineComment:
|
126
|
+
Enabled: false
|
127
|
+
Style/Lambda:
|
128
|
+
Enabled: false
|
129
|
+
Style/LambdaCall:
|
130
|
+
Enabled: false
|
131
|
+
Style/LineEndConcatenation:
|
132
|
+
Enabled: false
|
133
|
+
Style/MethodCalledOnDoEndBlock:
|
134
|
+
Enabled: false
|
135
|
+
Style/ModuleFunction:
|
136
|
+
Enabled: false
|
137
|
+
Style/NegatedIf:
|
138
|
+
Enabled: false
|
139
|
+
Style/NegatedWhile:
|
140
|
+
Enabled: false
|
141
|
+
Style/Next:
|
142
|
+
Enabled: false
|
143
|
+
Style/NilComparison:
|
144
|
+
Enabled: false
|
145
|
+
Style/Not:
|
146
|
+
Enabled: false
|
147
|
+
Style/NumericLiterals:
|
148
|
+
Enabled: false
|
149
|
+
Style/NumericPredicate:
|
150
|
+
Enabled: false
|
151
|
+
Style/OneLineConditional:
|
152
|
+
Enabled: false
|
153
|
+
Style/PercentLiteralDelimiters:
|
154
|
+
Enabled: false
|
155
|
+
Style/PerlBackrefs:
|
156
|
+
Enabled: false
|
157
|
+
Style/PreferredHashMethods:
|
158
|
+
Enabled: false
|
159
|
+
Style/Proc:
|
160
|
+
Enabled: false
|
161
|
+
Style/RaiseArgs:
|
162
|
+
Enabled: false
|
163
|
+
Style/RegexpLiteral:
|
164
|
+
Enabled: false
|
165
|
+
Style/RescueStandardError:
|
166
|
+
Enabled: false
|
167
|
+
Style/SelfAssignment:
|
168
|
+
Enabled: false
|
169
|
+
Style/SignalException:
|
170
|
+
Enabled: false
|
171
|
+
Style/SingleLineBlockParams:
|
172
|
+
Enabled: false
|
173
|
+
Style/SingleLineMethods:
|
174
|
+
Enabled: false
|
175
|
+
Style/SpecialGlobalVars:
|
176
|
+
Enabled: false
|
177
|
+
Style/StringLiterals:
|
178
|
+
EnforcedStyle: double_quotes
|
179
|
+
Style/SymbolArray:
|
180
|
+
Enabled: false
|
181
|
+
Style/TrivialAccessors:
|
182
|
+
Enabled: false
|
183
|
+
Style/WhenThen:
|
184
|
+
Enabled: false
|
185
|
+
Style/WhileUntilModifier:
|
186
|
+
Enabled: false
|
187
|
+
Style/WordArray:
|
188
|
+
Enabled: false
|
189
|
+
Style/VariableInterpolation:
|
190
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.1
|
data/.travis.yml
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache:
|
4
|
+
directories:
|
5
|
+
- vendor/bundle
|
6
|
+
script: "bundle exec rake"
|
7
|
+
# Source: <https://docs.travis-ci.com/user/languages/ruby/#bundler-20>
|
8
|
+
before_install:
|
9
|
+
- gem update --system '2.7.8' --no-document
|
10
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
11
|
+
- gem install bundler -v '< 2' --no-document
|
12
|
+
install: "bundle install --jobs=3 --retry=3 --path vendor/bundle"
|
13
|
+
|
1
14
|
rvm:
|
2
|
-
-
|
3
|
-
- 2.
|
15
|
+
- 2.6.1
|
16
|
+
- 2.5.1
|
17
|
+
- 2.4.4
|
18
|
+
- 2.3.7
|
19
|
+
|
20
|
+
env:
|
21
|
+
- TEST_FRAMEWORK=minitest
|
22
|
+
- TEST_FRAMEWORK=test_unit
|
23
|
+
|
24
|
+
gemfile:
|
25
|
+
- gemfiles/rails_4_2.gemfile
|
26
|
+
- gemfiles/rails_5_0.gemfile
|
27
|
+
- gemfiles/rails_5_1.gemfile
|
28
|
+
- gemfiles/rails_5_2.gemfile
|
data/Appraisals
CHANGED
@@ -1,44 +1,27 @@
|
|
1
|
-
|
2
|
-
gem
|
3
|
-
gem 'sqlite3'
|
1
|
+
shared_dependencies = proc do
|
2
|
+
gem "sqlite3", "~> 1.3.6"
|
4
3
|
end
|
5
4
|
|
6
|
-
appraise
|
7
|
-
|
8
|
-
gem 'jquery-rails'
|
9
|
-
gem 'sass-rails'
|
10
|
-
gem 'sqlite3'
|
11
|
-
end
|
5
|
+
appraise "rails_4_2" do
|
6
|
+
instance_eval(&shared_dependencies)
|
12
7
|
|
13
|
-
|
14
|
-
gem 'rails', '~> 3.2.0'
|
15
|
-
gem 'jquery-rails'
|
16
|
-
gem 'sass-rails'
|
17
|
-
gem 'sqlite3'
|
8
|
+
gem "rails", "~> 4.2.0"
|
18
9
|
end
|
19
10
|
|
20
|
-
appraise
|
21
|
-
|
22
|
-
gem 'jquery-rails'
|
23
|
-
gem 'sass-rails'
|
24
|
-
gem 'sqlite3'
|
25
|
-
end
|
11
|
+
appraise "rails_5_0" do
|
12
|
+
instance_eval(&shared_dependencies)
|
26
13
|
|
27
|
-
|
28
|
-
gem 'rails', github: 'rails/rails', branch: '4-1-stable'
|
29
|
-
gem 'jquery-rails'
|
30
|
-
gem 'sass-rails'
|
31
|
-
gem 'sqlite3'
|
14
|
+
gem "rails", "~> 5.0.0"
|
32
15
|
end
|
33
16
|
|
34
|
-
appraise
|
35
|
-
|
36
|
-
end
|
17
|
+
appraise "rails_5_1" do
|
18
|
+
instance_eval(&shared_dependencies)
|
37
19
|
|
38
|
-
|
39
|
-
gem 'minitest', '~> 5.0'
|
20
|
+
gem "rails", "~> 5.1.0"
|
40
21
|
end
|
41
22
|
|
42
|
-
appraise
|
43
|
-
|
23
|
+
appraise "rails_5_2" do
|
24
|
+
instance_eval(&shared_dependencies)
|
25
|
+
|
26
|
+
gem "rails", "~> 5.2.0"
|
44
27
|
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 2.0.0 (unreleased)
|
4
|
+
|
5
|
+
### Backward-incompatible changes
|
6
|
+
|
7
|
+
* Drop support for RSpec 2 matchers. Matchers passed to `should` must conform
|
8
|
+
to RSpec 3's API (`failure_message` and `failure_message_when_negated`).
|
9
|
+
* Drop support for Minitest 4.x (last updated in 2013).
|
10
|
+
* Drop support for end-of-lifed versions of Rails. Rails 4.2.x, 5.1.x, and 5.2.x
|
11
|
+
are the only versions supported now.
|
12
|
+
* Drop support for end-of-lifed versions of Ruby. Ruby 2.3.x, 2.4.x and 2.5.x
|
13
|
+
are the only versions supported now.
|
14
|
+
|
15
|
+
### Bug fixes
|
16
|
+
|
17
|
+
* Fix how test names are generated so that when including the name of the
|
18
|
+
outermost test class, "Test" is not removed from the class name if it does not
|
19
|
+
fall at the end.
|
20
|
+
* Remove warning from Ruby about `context` not being used when using the gem
|
21
|
+
with warnings enabled.
|
22
|
+
* Fix macro autoloading code. Files intended to hold custom macros which are
|
23
|
+
located in either `test/shoulda_macros`, `vendor/gems/*/shoulda_macros`, or
|
24
|
+
`vendor/plugins/*/shoulda_macros` are now loaded and mixed into your test
|
25
|
+
framework's automatically.
|
26
|
+
* Restore compatibility with Shoulda Matchers, starting from 3.0.
|
27
|
+
* Fix some compatibility issues with Minitest 5.
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
shoulda-context (2.0.0.rc1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (2.2.0)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
thor (>= 0.14.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
byebug (10.0.2)
|
15
|
+
coderay (1.1.2)
|
16
|
+
jaro_winkler (1.5.2)
|
17
|
+
m (1.5.1)
|
18
|
+
method_source (>= 0.6.7)
|
19
|
+
rake (>= 0.9.2.2)
|
20
|
+
metaclass (0.0.4)
|
21
|
+
method_source (0.9.2)
|
22
|
+
minitest (5.11.3)
|
23
|
+
mocha (1.8.0)
|
24
|
+
metaclass (~> 0.0.1)
|
25
|
+
parallel (1.14.0)
|
26
|
+
parser (2.6.0.0)
|
27
|
+
ast (~> 2.4.0)
|
28
|
+
power_assert (1.1.3)
|
29
|
+
powerpack (0.1.2)
|
30
|
+
pry (0.12.2)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.9.0)
|
33
|
+
pry-byebug (3.6.0)
|
34
|
+
byebug (~> 10.0)
|
35
|
+
pry (~> 0.10)
|
36
|
+
psych (3.1.0)
|
37
|
+
rainbow (3.0.0)
|
38
|
+
rake (12.3.2)
|
39
|
+
rubocop (0.65.0)
|
40
|
+
jaro_winkler (~> 1.5.1)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 2.5, != 2.5.1.1)
|
43
|
+
powerpack (~> 0.1)
|
44
|
+
psych (>= 3.1.0)
|
45
|
+
rainbow (>= 2.2.2, < 4.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (~> 1.4.0)
|
48
|
+
ruby-progressbar (1.10.0)
|
49
|
+
snowglobe (0.1.0)
|
50
|
+
test-unit (3.3.0)
|
51
|
+
power_assert
|
52
|
+
thor (0.20.3)
|
53
|
+
unicode-display_width (1.4.1)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
appraisal
|
60
|
+
bundler (~> 1.0)
|
61
|
+
m
|
62
|
+
minitest
|
63
|
+
mocha
|
64
|
+
pry-byebug
|
65
|
+
rake
|
66
|
+
rubocop
|
67
|
+
shoulda-context!
|
68
|
+
snowglobe
|
69
|
+
test-unit
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.17.3
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,22 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# Shoulda Context [![Gem Version][version-badge]][rubygems] [![Build Status][travis-badge]][travis] ![Downloads][downloads-badge] [![Hound][hound-badge]][hound]
|
2
2
|
|
3
|
-
[
|
3
|
+
[version-badge]: https://img.shields.io/gem/v/shoulda-context.svg
|
4
|
+
[rubygems]: https://rubygems.org/gems/shoulda-matchers
|
5
|
+
[travis-badge]: https://img.shields.io/travis/thoughtbot/shoulda-context/master.svg
|
6
|
+
[travis]: https://travis-ci.org/thoughtbot/shoulda-context
|
7
|
+
[downloads-badge]: https://img.shields.io/gem/dtv/shoulda-context.svg
|
8
|
+
[hound-badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
9
|
+
[hound]: https://houndci.com
|
4
10
|
|
5
|
-
Shoulda
|
6
|
-
|
11
|
+
Shoulda Context makes it easy to write understandable and maintainable tests
|
12
|
+
under Minitest and Test::Unit within Rails projects or plain Ruby projects. It's
|
13
|
+
fully compatible with your existing tests and requires no retooling to use.
|
7
14
|
|
8
|
-
|
9
|
-
|
15
|
+
**[View the documentation for the latest version (1.2.2)][rubydocs] • [View
|
16
|
+
the changelog][changelog]**
|
10
17
|
|
11
|
-
|
18
|
+
[changelog]: CHANGELOG.md
|
12
19
|
|
13
|
-
|
14
|
-
context, setup, and should blocks...
|
20
|
+
---
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Instead of writing Ruby methods with `lots_of_underscores`, Shoulda Context lets
|
25
|
+
you name your tests and group them together using English.
|
26
|
+
|
27
|
+
At a minimum, the gem provides some convenience layers around core Minitest
|
28
|
+
functionality. For instance, this test case:
|
18
29
|
|
19
|
-
|
30
|
+
```ruby
|
31
|
+
class CalculatorTest < Minitest::Test
|
20
32
|
context "a calculator" do
|
21
33
|
setup do
|
22
34
|
@calculator = Calculator.new
|
@@ -33,35 +45,134 @@ class CalculatorTest < Test::Unit::TestCase
|
|
33
45
|
end
|
34
46
|
```
|
35
47
|
|
36
|
-
|
48
|
+
is a prettier, but functionally equivalent, way of saying:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class CalculatorTest < Minitest::Test
|
52
|
+
def setup
|
53
|
+
@calculator = Calculator.new
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method "test_: a calculator should add two numbers for the sum" do
|
57
|
+
assert_equal 4, @calculator.sum(2, 2)
|
58
|
+
end
|
59
|
+
|
60
|
+
define_method "test_: a calculator should multiply two numbers for the product" do
|
61
|
+
assert_equal 10, @calculator.product(2, 5)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
However, Shoulda Context also provides functionality apart from Minitest /
|
67
|
+
Test::Unit that allows you to shorten tests drastically by making use of
|
68
|
+
RSpec-compatible matchers. For instance, with [Shoulda
|
69
|
+
Matchers][shoulda-matchers] you can write such tests as:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
class User < ActiveSupport::TestCase
|
73
|
+
context "validations" do
|
74
|
+
subject { FactoryBot.build(:user) }
|
75
|
+
|
76
|
+
should validate_presence_of(:first_name)
|
77
|
+
should validate_presence_of(:last_name)
|
78
|
+
should validate_uniqueness_of(:email)
|
79
|
+
should_not allow_value('weird').for(:email)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
[shoulda-matchers]: https://github.com/thoughtbot/shoulda-matchers
|
85
|
+
|
86
|
+
## API
|
87
|
+
|
88
|
+
### DSL
|
89
|
+
|
90
|
+
The primary method in Shoulda Context's API is `context`, which declares a group
|
91
|
+
of a tests.
|
92
|
+
|
93
|
+
These methods are available inside of a `context`:
|
94
|
+
|
95
|
+
* `setup` — a DSL-y alternative to defining a `setup` method
|
96
|
+
* `teardown` — a DSL-y alternative to defining a `teardown` method
|
97
|
+
* `should` — There are two forms:
|
98
|
+
1. when passed a name + block, creates a test equivalent to defining a
|
99
|
+
`test_` method
|
100
|
+
2. when passed a matcher, creates a test that will run the matcher, asserting
|
101
|
+
that it passes
|
102
|
+
* `should_not` — like the matcher version of `should`, but creates a test that
|
103
|
+
asserts that the matcher fails
|
104
|
+
* `should_eventually` — allows you to temporarily skip tests
|
105
|
+
* `context` — creates a subcontext
|
106
|
+
|
107
|
+
These methods are available within a test case class, but outside of a
|
108
|
+
`context`:
|
109
|
+
|
110
|
+
* `should` — same as above
|
111
|
+
* `should_not` — same as above
|
112
|
+
* `should_eventually` — same as above
|
113
|
+
* `described_type` — returns the class being tested, as determined by the class
|
114
|
+
name of the outermost class
|
115
|
+
* `subject` — lets you define an object that is the primary focus of the tests
|
116
|
+
within a context; this is most useful when using a matcher as the matcher will
|
117
|
+
make use of this as _its_ subject
|
37
118
|
|
38
|
-
|
39
|
-
|
119
|
+
And these methods are available inside of a test (whether defined via a method
|
120
|
+
or via `should`):
|
40
121
|
|
41
|
-
|
122
|
+
* `subject` — an instance of the class under test, which is derived
|
123
|
+
automatically from the name of the test case class but is overridable via the
|
124
|
+
class method version of `subject` above
|
42
125
|
|
43
|
-
|
126
|
+
[rubydocs]: http://rubydoc.info/github/thoughtbot/shoulda-context/master/frames
|
44
127
|
|
45
|
-
|
128
|
+
### Assertions
|
46
129
|
|
47
|
-
|
130
|
+
In addition to the main API, the gem also provides some extra assertions that
|
131
|
+
may be of use:
|
48
132
|
|
133
|
+
* `assert_same_elements` — compares two arrays for equality, but ignoring
|
134
|
+
ordering
|
135
|
+
* `assert_contains` — asserts that an array has an item
|
136
|
+
* `assert_does_not_contain` — the opposite of `assert_contains`
|
137
|
+
* `assert_accepts` — what `should` uses internally; asserts that a matcher
|
138
|
+
object matches against a value
|
139
|
+
* `assert_reject` — what `should_not` uses internally; asserts that a matcher
|
140
|
+
object does not match against a value
|
49
141
|
|
50
|
-
##
|
142
|
+
## Note on running tests
|
51
143
|
|
52
|
-
|
144
|
+
Normally, you will run a single test like this:
|
53
145
|
|
54
|
-
|
55
|
-
|
56
|
-
|
146
|
+
ruby -I lib -I test path_to_test.rb -n name_of_test_method
|
147
|
+
|
148
|
+
When using Shoulda Context, however, you'll need to put a space after the test
|
149
|
+
name:
|
150
|
+
|
151
|
+
ruby -I lib -I test path_to_test.rb -n "test_: a calculator should add two numbers for the sum. "
|
152
|
+
|
153
|
+
If this is too cumbersome, consider using the [m] gem to run tests instead:
|
154
|
+
|
155
|
+
m path_to_test.rb:39
|
156
|
+
|
157
|
+
[m]: https://github.com/qrush/m
|
158
|
+
|
159
|
+
## Compatibility
|
160
|
+
|
161
|
+
Shoulda Context is tested and supported against Rails 5.x, Rails 4.2, Minitest
|
162
|
+
5, Test::Unit 3, and Ruby 2.3+.
|
57
163
|
|
58
164
|
## Credits
|
59
165
|
|
60
|
-
Shoulda is maintained
|
61
|
-
|
62
|
-
|
166
|
+
Shoulda Context is maintained by [Travis Jeffery][travis-jeffery] and
|
167
|
+
thoughtbot. Thank you to all the [contributors].
|
168
|
+
|
169
|
+
[travis-jeffery]: https://github.com/travisjeffery
|
170
|
+
[contributors]: https://github.com/thoughtbot/shoulda-context/contributors
|
63
171
|
|
64
172
|
## License
|
65
173
|
|
66
|
-
Shoulda is
|
67
|
-
It is free software, and may be redistributed under the terms specified in the
|
174
|
+
Shoulda Context is copyright © 2006-2019 [thoughtbot, inc][thoughtbot-website].
|
175
|
+
It is free software, and may be redistributed under the terms specified in the
|
176
|
+
[MIT-LICENSE](MIT-LICENSE) file.
|
177
|
+
|
178
|
+
[thoughtbot-website]: https://thoughtbot.com
|