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.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +190 -0
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +27 -2
  6. data/Appraisals +15 -32
  7. data/CHANGELOG.md +27 -0
  8. data/Gemfile +4 -1
  9. data/Gemfile.lock +72 -0
  10. data/MIT-LICENSE +1 -1
  11. data/README.md +140 -29
  12. data/Rakefile +19 -14
  13. data/bin/install_gems_in_all_appraisals +16 -0
  14. data/bin/run_all_tests +16 -0
  15. data/bin/setup +190 -0
  16. data/bin/supported_ruby_versions +7 -0
  17. data/bin/update_gem_in_all_appraisals +17 -0
  18. data/bin/update_gems_in_all_appraisals +16 -0
  19. data/{bin → exe}/convert_to_should_syntax +0 -0
  20. data/gemfiles/rails_4_2.gemfile +10 -0
  21. data/gemfiles/rails_4_2.gemfile.lock +164 -0
  22. data/gemfiles/rails_5_0.gemfile +10 -0
  23. data/gemfiles/rails_5_0.gemfile.lock +170 -0
  24. data/gemfiles/rails_5_1.gemfile +10 -0
  25. data/gemfiles/rails_5_1.gemfile.lock +170 -0
  26. data/gemfiles/rails_5_2.gemfile +10 -0
  27. data/gemfiles/rails_5_2.gemfile.lock +178 -0
  28. data/lib/shoulda/context.rb +12 -16
  29. data/lib/shoulda/context/assertions.rb +16 -13
  30. data/lib/shoulda/context/configuration.rb +19 -0
  31. data/lib/shoulda/context/context.rb +22 -305
  32. data/lib/shoulda/context/dsl.rb +279 -0
  33. data/lib/shoulda/context/railtie.rb +14 -0
  34. data/lib/shoulda/context/test_framework_detection.rb +4 -5
  35. data/lib/shoulda/context/version.rb +1 -1
  36. data/lib/shoulda/context/world.rb +22 -0
  37. data/shoulda-context.gemspec +19 -17
  38. data/test/fake_rails_root/test/shoulda_macros/custom_macro.rb +1 -1
  39. data/test/fake_rails_root/vendor/gems/gem_with_macro-0.0.1/shoulda_macros/gem_macro.rb +1 -2
  40. data/test/fake_rails_root/vendor/plugins/plugin_with_macro/shoulda_macros/plugin_macro.rb +1 -2
  41. data/test/shoulda/autoload_macro_test.rb +1 -1
  42. data/test/shoulda/context_test.rb +92 -53
  43. data/test/shoulda/convert_to_should_syntax_test.rb +5 -7
  44. data/test/shoulda/helpers_test.rb +24 -59
  45. data/test/shoulda/railtie_test.rb +43 -0
  46. data/test/shoulda/should_test.rb +163 -24
  47. data/test/shoulda/test_framework_detection_test.rb +64 -71
  48. data/test/support/current_bundle.rb +61 -0
  49. data/test/support/rails_application_with_shoulda_context.rb +46 -0
  50. data/test/support/snowglobe.rb +5 -0
  51. data/test/test_helper.rb +35 -11
  52. metadata +71 -60
  53. data/gemfiles/minitest_4_x.gemfile +0 -7
  54. data/gemfiles/minitest_4_x.gemfile.lock +0 -96
  55. data/gemfiles/minitest_5_x.gemfile +0 -7
  56. data/gemfiles/minitest_5_x.gemfile.lock +0 -102
  57. data/gemfiles/rails_3_0.gemfile +0 -8
  58. data/gemfiles/rails_3_0.gemfile.lock +0 -93
  59. data/gemfiles/rails_3_1.gemfile +0 -10
  60. data/gemfiles/rails_3_1.gemfile.lock +0 -114
  61. data/gemfiles/rails_3_2.gemfile +0 -10
  62. data/gemfiles/rails_3_2.gemfile.lock +0 -112
  63. data/gemfiles/rails_4_0.gemfile +0 -10
  64. data/gemfiles/rails_4_0.gemfile.lock +0 -107
  65. data/gemfiles/rails_4_1.gemfile +0 -10
  66. data/gemfiles/rails_4_1.gemfile.lock +0 -119
  67. data/gemfiles/test_unit.gemfile +0 -7
  68. data/gemfiles/test_unit.gemfile.lock +0 -95
  69. data/init.rb +0 -1
  70. data/rails/init.rb +0 -4
@@ -1,9 +1,8 @@
1
- require 'test/unit'
2
-
3
- class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc:
1
+ require 'test_helper'
4
2
 
3
+ class ConvertToShouldSyntaxTest < PARENT_TEST_CASE
5
4
  BEFORE_FIXTURE = <<-EOS
6
- class DummyTest < Test::Unit::TestCase
5
+ class DummyTest < #{PARENT_TEST_CASE}
7
6
 
8
7
  should "Not change this_word_with_underscores" do
9
8
  end
@@ -23,7 +22,7 @@ class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc:
23
22
  EOS
24
23
 
25
24
  AFTER_FIXTURE = <<-EOS
26
- class DummyTest < Test::Unit::TestCase
25
+ class DummyTest < #{PARENT_TEST_CASE}
27
26
 
28
27
  should "Not change this_word_with_underscores" do
29
28
  end
@@ -48,7 +47,7 @@ class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc:
48
47
 
49
48
  def test_convert_to_should_syntax
50
49
  File.open(FIXTURE_PATH, "w") {|f| f.write(BEFORE_FIXTURE)}
51
- cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../bin/convert_to_should_syntax')} #{FIXTURE_PATH}"
50
+ cmd = "#{RUBY} #{File.join(File.dirname(__FILE__), '../../exe/convert_to_should_syntax')} #{FIXTURE_PATH}"
52
51
  output = `#{cmd}`
53
52
  File.unlink($1) if output.match(/has been stored in '([^']+)/)
54
53
  assert_match(/has been converted/, output)
@@ -59,5 +58,4 @@ class ConvertToShouldSyntaxTest < Test::Unit::TestCase # :nodoc:
59
58
  def teardown
60
59
  File.unlink(FIXTURE_PATH)
61
60
  end
62
-
63
61
  end
@@ -1,7 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class HelpersTest < Test::Unit::TestCase # :nodoc:
4
-
3
+ class HelpersTest < PARENT_TEST_CASE
5
4
  context "an array of values" do
6
5
  setup do
7
6
  @a = ['abc', 'def', 3]
@@ -9,7 +8,7 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
9
8
 
10
9
  [/b/, 'abc', 3].each do |x|
11
10
  should "contain #{x.inspect}" do
12
- assert_raises(Test::Unit::AssertionFailedError) do
11
+ assert_raises(ASSERTION_CLASS) do
13
12
  assert_does_not_contain @a, x
14
13
  end
15
14
  assert_contains @a, x
@@ -17,17 +16,17 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
17
16
  end
18
17
 
19
18
  should "not contain 'wtf'" do
20
- assert_raises(Test::Unit::AssertionFailedError) {assert_contains @a, 'wtf'}
19
+ assert_raises(ASSERTION_CLASS) {assert_contains @a, 'wtf'}
21
20
  assert_does_not_contain @a, 'wtf'
22
21
  end
23
22
 
24
23
  should "be the same as another array, ordered differently" do
25
24
  assert_same_elements(@a, [3, "def", "abc"])
26
- assert_raises(Test::Unit::AssertionFailedError) do
25
+ assert_raises(ASSERTION_CLASS) do
27
26
  assert_same_elements(@a, [3, 3, "def", "abc"])
28
27
  end
29
28
  assert_same_elements([@a, "abc"].flatten, ["abc", 3, "def", "abc"])
30
- assert_raises(Test::Unit::AssertionFailedError) do
29
+ assert_raises(ASSERTION_CLASS) do
31
30
  assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
32
31
  end
33
32
  end
@@ -41,9 +40,12 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
41
40
 
42
41
  context "a matching matcher" do
43
42
  setup do
44
- @matcher = stub('matcher', :matches? => true,
45
- :failure_message_for_should => 'bad failure message',
46
- :failure_message_for_should_not => 'big time failure')
43
+ @matcher = stub(
44
+ "matcher",
45
+ matches?: true,
46
+ failure_message: "bad failure message",
47
+ failure_message_when_negated: "big time failure"
48
+ )
47
49
  end
48
50
 
49
51
  should "pass when given to assert_accepts with no message expectation" do
@@ -55,7 +57,7 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
55
57
  end
56
58
 
57
59
  should "fail when given to assert_accepts with non-matching message" do
58
- assert_raise Test::Unit::AssertionFailedError do
60
+ assert_raises ASSERTION_CLASS do
59
61
  assert_accepts @matcher, 'target', :message => /small time/
60
62
  end
61
63
  end
@@ -68,7 +70,7 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
68
70
  @matcher.stubs(:matches?).returns(false)
69
71
  @matcher.stubs(:does_not_match?).returns(true)
70
72
  assert_rejects @matcher, 'target'
71
- rescue Test::Unit::AssertionFailedError => @error
73
+ rescue ASSERTION_CLASS => @error
72
74
  end
73
75
  end
74
76
 
@@ -82,12 +84,12 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
82
84
  @error = nil
83
85
  begin
84
86
  assert_rejects @matcher, 'target'
85
- rescue Test::Unit::AssertionFailedError => @error
87
+ rescue ASSERTION_CLASS => @error
86
88
  end
87
89
  end
88
90
 
89
91
  should "fail" do
90
- assert_not_nil @error
92
+ refute_nil @error
91
93
  end
92
94
 
93
95
  should "use the error message from the matcher" do
@@ -99,49 +101,12 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
99
101
 
100
102
  context "a non-matching matcher" do
101
103
  setup do
102
- @matcher = stub('matcher', :matches? => false,
103
- :failure_message_for_should => 'big time failure',
104
- :failure_message_for_should_not => 'bad failure message')
105
- end
106
-
107
- should "pass when given to assert_rejects with no message expectation" do
108
- assert_rejects @matcher, 'target'
109
- end
110
-
111
- should "pass when given to assert_rejects with a matching message" do
112
- assert_rejects @matcher, 'target', :message => /big time/
113
- end
114
-
115
- should "fail when given to assert_rejects with a non-matching message" do
116
- assert_raise Test::Unit::AssertionFailedError do
117
- assert_rejects @matcher, 'target', :message => /small time/
118
- end
119
- end
120
-
121
- context "when given to assert_accepts" do
122
- setup do
123
- begin
124
- assert_accepts @matcher, 'target'
125
- rescue Test::Unit::AssertionFailedError => @error
126
- end
127
- end
128
-
129
- should "fail" do
130
- assert_not_nil @error
131
- end
132
-
133
- should "use the error message from the matcher" do
134
- assert_equal 'big time failure', @error.message
135
- end
136
- end
137
- end
138
-
139
-
140
- context "a matcher using antiquated syntax" do
141
- setup do
142
- @matcher = stub('matcher', :matches? => false,
143
- :failure_message => 'big time failure',
144
- :negative_failure_message => 'bad failure message')
104
+ @matcher = stub(
105
+ "matcher",
106
+ matches?: false,
107
+ failure_message: "big time failure",
108
+ failure_message_when_negated: "bad failure message"
109
+ )
145
110
  end
146
111
 
147
112
  should "pass when given to assert_rejects with no message expectation" do
@@ -153,7 +118,7 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
153
118
  end
154
119
 
155
120
  should "fail when given to assert_rejects with a non-matching message" do
156
- assert_raise Test::Unit::AssertionFailedError do
121
+ assert_raises ASSERTION_CLASS do
157
122
  assert_rejects @matcher, 'target', :message => /small time/
158
123
  end
159
124
  end
@@ -162,12 +127,12 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
162
127
  setup do
163
128
  begin
164
129
  assert_accepts @matcher, 'target'
165
- rescue Test::Unit::AssertionFailedError => @error
130
+ rescue ASSERTION_CLASS => @error
166
131
  end
167
132
  end
168
133
 
169
134
  should "fail" do
170
- assert_not_nil @error
135
+ refute_nil @error
171
136
  end
172
137
 
173
138
  should "use the error message from the matcher" do
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ class RailtieTest < PARENT_TEST_CASE
4
+ context "A Rails application with shoulda-context added to it" do
5
+ setup do
6
+ app.create
7
+ end
8
+
9
+ should "load files in vendor/gems and vendor/plugins when booted" do
10
+ app.create_gem_with_macro(
11
+ module_name: "MacrosFromVendor",
12
+ location: "vendor/gems/vendored_gem_with_macro",
13
+ macro_name: "macro_from_vendored_gem"
14
+ )
15
+ app.create_gem_with_macro(
16
+ module_name: "MacrosFromPlugin",
17
+ location: "vendor/plugins/plugin_gem_with_macro",
18
+ macro_name: "macro_from_plugin_gem"
19
+ )
20
+ app.create_gem_with_macro(
21
+ module_name: "MacrosFromTest",
22
+ location: "test",
23
+ macro_name: "macro_from_test"
24
+ )
25
+ app.write_file("test/macros_test.rb", <<~RUBY)
26
+ ENV["RAILS_ENV"] = "test"
27
+ require_relative "../config/environment"
28
+
29
+ class MacrosTest < #{PARENT_TEST_CASE}
30
+ macro_from_vendored_gem
31
+ macro_from_plugin_gem
32
+ macro_from_test
33
+ end
34
+ RUBY
35
+
36
+ app.run_command!("bundle exec rake test")
37
+ end
38
+ end
39
+
40
+ def app
41
+ @_app ||= RailsApplicationWithShouldaContext.new
42
+ end
43
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ShouldTest < Test::Unit::TestCase # :nodoc:
3
+ class ShouldTest < PARENT_TEST_CASE
4
4
  should "be able to define a should statement outside of a context" do
5
5
  assert true
6
6
  end
@@ -19,7 +19,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
19
19
  should "be able to setup a should eventually in a class method"
20
20
  end
21
21
 
22
- def self.should_see_a_context_block_like_a_Test_Unit_class
22
+ def self.should_see_a_context_block_like_a_test_case_class
23
23
  should "see a context block as a Test::Unit class" do
24
24
  assert_equal "ShouldTest", self.class.name
25
25
  end
@@ -40,14 +40,22 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
40
40
  def self.should_be_able_to_make_context_macros(prefix = nil)
41
41
  context "a macro" do
42
42
  should "have the tests named correctly" do
43
- assert_match(/^test: #{prefix}a macro should have the tests named correctly/, self.to_s)
43
+ assert_match(
44
+ Regexp.new(
45
+ "^" +
46
+ build_expected_test_name(
47
+ "#{prefix}a macro should have the tests named correctly"
48
+ )
49
+ ),
50
+ test_name
51
+ )
44
52
  end
45
53
  end
46
54
  end
47
55
 
48
56
  context "Context" do
49
57
  should_see_class_methods
50
- should_see_a_context_block_like_a_Test_Unit_class
58
+ should_see_a_context_block_like_a_test_case_class
51
59
  should_be_able_to_make_context_macros("Context ")
52
60
  should_be_able_to_setup_a_should_eventually_in_a_class_method
53
61
 
@@ -81,7 +89,13 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
81
89
  should_see_blah
82
90
 
83
91
  should "have name set right" do
84
- assert_match(/^test: Context with setup block/, self.to_s)
92
+ assert_match(
93
+ Regexp.new(
94
+ "^" +
95
+ build_expected_test_name("Context with setup block")
96
+ ),
97
+ test_name
98
+ )
85
99
  end
86
100
 
87
101
  context "and a subcontext" do
@@ -90,7 +104,15 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
90
104
  end
91
105
 
92
106
  should "be named correctly" do
93
- assert_match(/^test: Context with setup block and a subcontext should be named correctly/, self.to_s)
107
+ assert_match(
108
+ Regexp.new(
109
+ "^" +
110
+ build_expected_test_name(
111
+ "Context with setup block and a subcontext should be named correctly"
112
+ )
113
+ ),
114
+ test_name
115
+ )
94
116
  end
95
117
 
96
118
  should "run the setup methods in order" do
@@ -110,7 +132,13 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
110
132
  end
111
133
 
112
134
  should "have name set right" do
113
- assert_match(/^test: Another context with setup block/, self.to_s)
135
+ assert_match(
136
+ Regexp.new(
137
+ "^" +
138
+ build_expected_test_name("Another context with setup block")
139
+ ),
140
+ test_name
141
+ )
114
142
  end
115
143
  should_see_blah
116
144
  end
@@ -123,14 +151,14 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
123
151
 
124
152
  def test_should_create_a_new_context
125
153
  assert_nothing_raised do
126
- Shoulda::Context::Context.new("context name", self) do; end
154
+ Shoulda::Context::Context.new("context name", self.class) do; end
127
155
  end
128
156
  end
129
157
 
130
158
  def test_should_create_a_new_context_even_if_block_is_omitted
131
159
  old_verbose, $VERBOSE = $VERBOSE, nil
132
160
  assert_nothing_raised do
133
- Shoulda::Context::Context.new("context without a block", self)
161
+ Shoulda::Context::Context.new("context without a block", self.class)
134
162
  end
135
163
  ensure
136
164
  $VERBOSE = old_verbose
@@ -138,14 +166,14 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
138
166
 
139
167
  def test_should_create_a_nested_context
140
168
  assert_nothing_raised do
141
- parent = Shoulda::Context::Context.new("Parent", self) do; end
169
+ parent = Shoulda::Context::Context.new("Parent", self.class) do; end
142
170
  child = Shoulda::Context::Context.new("Child", parent) do; end
143
171
  raise unless child.instance_of? Shoulda::Context::Context
144
172
  end
145
173
  end
146
174
 
147
175
  def test_should_name_a_contexts_correctly
148
- parent = Shoulda::Context::Context.new("Parent", self) do; end
176
+ parent = Shoulda::Context::Context.new("Parent", self.class) do; end
149
177
  child = Shoulda::Context::Context.new("Child", parent) do; end
150
178
  grandchild = Shoulda::Context::Context.new("GrandChild", child) do; end
151
179
 
@@ -155,12 +183,11 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
155
183
  end
156
184
 
157
185
  def test_should_raise_on_duplicate_naming
158
- tu_class = Test::Unit::TestCase
159
- context = Shoulda::Context::Context.new("DupContext", tu_class) do
186
+ context = Shoulda::Context::Context.new("DupContext", self.class) do
160
187
  should "dup" do; end
161
188
  should "dup" do; end
162
189
  end
163
- assert_raise DuplicateTestError do
190
+ assert_raises Shoulda::Context::DuplicateTestError do
164
191
  context.build
165
192
  end
166
193
  end
@@ -168,7 +195,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
168
195
  # Should statements
169
196
 
170
197
  def test_should_have_should_hashes_when_given_should_statements
171
- context = Shoulda::Context::Context.new("name", self) do
198
+ context = Shoulda::Context::Context.new("name", self.class) do
172
199
  should "be good" do; end
173
200
  should "another" do; end
174
201
  end
@@ -180,7 +207,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
180
207
  # setup and teardown
181
208
 
182
209
  def test_should_capture_setup_and_teardown_blocks
183
- context = Shoulda::Context::Context.new("name", self) do
210
+ context = Shoulda::Context::Context.new("name", self.class) do
184
211
  setup do; "setup"; end
185
212
  teardown do; "teardown"; end
186
213
  end
@@ -192,7 +219,7 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
192
219
  # building
193
220
 
194
221
  def test_should_create_shoulda_test_for_each_should_on_build
195
- context = Shoulda::Context::Context.new("name", self) do
222
+ context = Shoulda::Context::Context.new("name", self.class) do
196
223
  should "one" do; end
197
224
  should "two" do; end
198
225
  end
@@ -202,44 +229,54 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
202
229
  end
203
230
 
204
231
  def test_should_create_test_methods_on_build
205
- tu_class = Test::Unit::TestCase
232
+ tu_class = self.class
206
233
  context = Shoulda::Context::Context.new("A Context", tu_class) do
207
234
  should "define the test" do; end
208
235
  end
209
236
 
210
- tu_class.expects(:define_method).with(:"test: A Context should define the test. ")
237
+ tu_class.
238
+ expects(:define_method).
239
+ with(
240
+ build_expected_test_name("A Context should define the test. ").to_sym
241
+ )
211
242
  context.build
212
243
  end
213
244
 
214
245
  def test_should_create_test_methods_on_build_when_subcontext
215
- tu_class = Test::Unit::TestCase
246
+ tu_class = self.class
216
247
  context = Shoulda::Context::Context.new("A Context", tu_class) do
217
248
  context "with a child" do
218
249
  should "define the test" do; end
219
250
  end
220
251
  end
221
252
 
222
- tu_class.expects(:define_method).with(:"test: A Context with a child should define the test. ")
253
+ tu_class.
254
+ expects(:define_method).
255
+ with(
256
+ build_expected_test_name(
257
+ "A Context with a child should define the test. "
258
+ ).to_sym
259
+ )
223
260
  context.build
224
261
  end
225
262
 
226
263
  # Test::Unit integration
227
264
 
228
- def test_should_create_a_new_context_and_build_it_on_Test_Unit_context
265
+ def test_should_create_a_new_context_and_build_it_on_test_case_context
229
266
  c = mock("context")
230
267
  c.expects(:build)
231
268
  Shoulda::Context::Context.expects(:new).with("foo", kind_of(Class)).returns(c)
232
269
  self.class.context "foo" do; end
233
270
  end
234
271
 
235
- def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should
272
+ def test_should_create_a_one_off_context_and_build_it_on_test_case_should
236
273
  s = mock("test")
237
274
  Shoulda::Context::Context.any_instance.expects(:should).with("rock", {}).returns(s)
238
275
  Shoulda::Context::Context.any_instance.expects(:build)
239
276
  self.class.should "rock" do; end
240
277
  end
241
278
 
242
- def test_should_create_a_one_off_context_and_build_it_on_Test_Unit_should_eventually
279
+ def test_should_create_a_one_off_context_and_build_it_on_test_case_should_eventually
243
280
  s = mock("test")
244
281
  Shoulda::Context::Context.any_instance.expects(:should_eventually).with("rock").returns(s)
245
282
  Shoulda::Context::Context.any_instance.expects(:build)
@@ -288,4 +325,106 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
288
325
  end
289
326
  end
290
327
 
328
+ def test_name
329
+ name
330
+ end
331
+
332
+ def build_expected_test_name(value)
333
+ if TEST_FRAMEWORK == "minitest"
334
+ if value.is_a?(Regexp)
335
+ Regexp.new("^test_: #{value.source}")
336
+ else
337
+ "test_: #{value}"
338
+ end
339
+ elsif value.is_a?(Regexp)
340
+ Regexp.new("^test: #{value.source}")
341
+ else
342
+ "test: #{value}"
343
+ end
344
+ end
345
+
346
+ # Minitest removed assert_nothing_raised a while back;
347
+ # see here: <http://www.zenspider.com/ruby/2012/01/assert_nothing_tested.html>
348
+ def assert_nothing_raised
349
+ yield
350
+ end
351
+ end
352
+
353
+ class RedTestarossaDriver; end
354
+
355
+ class RedTestarossaDriverTest < PARENT_TEST_CASE
356
+ class DummyMatcher
357
+ def description
358
+ "fail to construct the proper test name with a 'should_not'"
359
+ end
360
+
361
+ def matches?(*)
362
+ false
363
+ end
364
+
365
+ def failure_message_when_negated
366
+ "dummy failure message"
367
+ end
368
+ end
369
+
370
+ should "call Shoulda::Context::Context.new using the correct context name" do
371
+ assert_equal "RedTestarossaDriver", @shoulda_context.name
372
+ end
373
+
374
+ should "see the name of the test case class as RedTestarossaDriverTest" do
375
+ assert_equal "RedTestarossaDriverTest", self.class.name
376
+ end
377
+
378
+ should "include the correct context name in the full name of the test" do
379
+ assert_match(
380
+ build_expected_test_name(/RedTestarossaDriver/),
381
+ test_name
382
+ )
383
+ end
384
+
385
+ def test_should_property_construct_test_name_for_should_eventually
386
+ context = Shoulda::Context::Context.new("whatever", self.class) do
387
+ "this is just a placeholder"
388
+ end
389
+
390
+ Shoulda::Context::Context.
391
+ expects(:new).
392
+ with("RedTestarossaDriver", RedTestarossaDriverTest).
393
+ returns(context)
394
+
395
+ self.class.should_eventually("do something") {}
396
+ end
397
+
398
+ def test_should_property_construct_test_name_for_should_not
399
+ context = Shoulda::Context::Context.new("whatever", self.class) do
400
+ "this is just a placeholder"
401
+ end
402
+
403
+ Shoulda::Context::Context.
404
+ expects(:new).
405
+ with("RedTestarossaDriver", RedTestarossaDriverTest).
406
+ returns(context)
407
+
408
+ self.class.should_not(DummyMatcher.new)
409
+ end
410
+
411
+ private
412
+
413
+ def test_name
414
+ name
415
+ end
416
+
417
+ def build_expected_test_name(value)
418
+ if TEST_FRAMEWORK == "minitest"
419
+ if value.is_a?(Regexp)
420
+ Regexp.new("^test_: #{value.source}")
421
+ else
422
+ "test_: #{value}"
423
+ end
424
+ elsif value.is_a?(Regexp)
425
+ Regexp.new("^test: #{value.source}")
426
+ else
427
+ "test: #{value}"
428
+ end
429
+ end
291
430
  end