shoulda-context 1.0.0.beta1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'mocha'
4
- gem 'ruby-debug'
5
-
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ shoulda-context (1.0.0.beta1)
5
+
1
6
  GEM
2
7
  remote: http://rubygems.org/
3
8
  specs:
4
- columnize (0.3.2)
5
- linecache (0.43)
6
- mocha (0.9.10)
7
- rake
8
- rake (0.8.7)
9
- ruby-debug (0.10.4)
10
- columnize (>= 0.1)
11
- ruby-debug-base (~> 0.10.4.0)
12
- ruby-debug-base (0.10.4)
13
- linecache (>= 0.3)
9
+ mocha (0.9.12)
10
+ rake (0.9.2.2)
11
+ test-unit (2.4.0)
14
12
 
15
13
  PLATFORMS
16
14
  ruby
17
15
 
18
16
  DEPENDENCIES
19
- mocha
20
- ruby-debug
17
+ mocha (~> 0.9.10)
18
+ rake
19
+ shoulda-context!
20
+ test-unit (~> 2.0)
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'rails', 'init')
@@ -1,12 +1 @@
1
- require 'test/unit'
2
- require 'shoulda/context/version'
3
- require 'shoulda/context/proc_extensions'
4
- require 'shoulda/context/assertions'
5
- require 'shoulda/context/context'
6
- require 'shoulda/context/autoload_macros'
7
-
8
- class Test::Unit::TestCase
9
- include Shoulda::Context::Assertions
10
- include Shoulda::Context::InstanceMethods
11
- extend Shoulda::Context::ClassMethods
12
- end
1
+ require "shoulda/context"
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+ require 'shoulda/context/version'
3
+ require 'shoulda/context/proc_extensions'
4
+ require 'shoulda/context/assertions'
5
+ require 'shoulda/context/context'
6
+ require 'shoulda/context/autoload_macros'
7
+
8
+ class Test::Unit::TestCase
9
+ include Shoulda::Context::Assertions
10
+ include Shoulda::Context::InstanceMethods
11
+ extend Shoulda::Context::ClassMethods
12
+ end
@@ -9,8 +9,8 @@ module Shoulda # :nodoc:
9
9
  [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
10
10
  end
11
11
 
12
- assert a1h = a1.inject({}) { |h,e| h[e] = a1.select { |i| i == e }.size; h }
13
- assert a2h = a2.inject({}) { |h,e| h[e] = a2.select { |i| i == e }.size; h }
12
+ assert a1h = a1.inject({}) { |h,e| h[e] ||= a1.select { |i| i == e }.size; h }
13
+ assert a2h = a2.inject({}) { |h,e| h[e] ||= a2.select { |i| i == e }.size; h }
14
14
 
15
15
  assert_equal(a1h, a2h, msg)
16
16
  end
@@ -22,7 +22,7 @@ module Shoulda # :nodoc:
22
22
  # assert_contains(['a', '1'], 'a') => passes
23
23
  # assert_contains(['a', '1'], /not there/) => fails
24
24
  def assert_contains(collection, x, extra_msg = "")
25
- collection = [collection] unless collection.is_a?(Array)
25
+ collection = Array(collection)
26
26
  msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
27
27
  case x
28
28
  when Regexp
@@ -35,7 +35,7 @@ module Shoulda # :nodoc:
35
35
  # Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
36
36
  # none of the elements from the collection match x.
37
37
  def assert_does_not_contain(collection, x, extra_msg = "")
38
- collection = [collection] unless collection.is_a?(Array)
38
+ collection = Array(collection)
39
39
  msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
40
40
  case x
41
41
  when Regexp
@@ -61,13 +61,16 @@ module Shoulda # :nodoc:
61
61
  end
62
62
  end
63
63
 
64
- # Asserts that the given matcher returns false when +target+ is passed to #matches?
64
+ # Asserts that the given matcher returns true when +target+ is passed to #does_not_match?
65
+ # or false when +target+ is passed to #matches? if #does_not_match? is not implemented
65
66
  def assert_rejects(matcher, target, options = {})
66
67
  if matcher.respond_to?(:in_context)
67
68
  matcher.in_context(self)
68
69
  end
69
70
 
70
- unless matcher.matches?(target)
71
+ not_match = matcher.respond_to?(:does_not_match?) ? matcher.does_not_match?(target) : !matcher.matches?(target)
72
+
73
+ if not_match
71
74
  assert_block { true }
72
75
  if options[:message]
73
76
  assert_match options[:message], matcher.failure_message
@@ -73,7 +73,7 @@ module Shoulda
73
73
  if Shoulda::Context.current_context
74
74
  Shoulda::Context.current_context.should(name_or_matcher, options, &blk)
75
75
  else
76
- context_name = self.name.gsub(/Test/, "")
76
+ context_name = self.name.gsub(/Test/, "") if self.name
77
77
  context = Shoulda::Context::Context.new(context_name, self) do
78
78
  should(name_or_matcher, options, &blk)
79
79
  end
@@ -92,7 +92,7 @@ module Shoulda
92
92
  if Shoulda::Context.current_context
93
93
  Shoulda::Context.current_context.should_not(matcher)
94
94
  else
95
- context_name = self.name.gsub(/Test/, "")
95
+ context_name = self.name.gsub(/Test/, "") if self.name
96
96
  context = Shoulda::Context::Context.new(context_name, self) do
97
97
  should_not(matcher)
98
98
  end
@@ -302,7 +302,11 @@ module Shoulda
302
302
  self.should_eventuallys = []
303
303
  self.subcontexts = []
304
304
 
305
- merge_block(&blk)
305
+ if block_given?
306
+ merge_block(&blk)
307
+ else
308
+ merge_block { warn " * WARNING: Block missing for context '#{full_name}'" }
309
+ end
306
310
  Shoulda::Context.remove_context
307
311
  end
308
312
 
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
2
  module Context
3
- VERSION = '1.0.0.beta1'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
data/rails/init.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  if RAILS_ENV == 'test'
2
- require 'shoulda-context'
2
+ require "shoulda/context"
3
3
  Shoulda.autoload_macros RAILS_ROOT, File.join("vendor", "{plugins,gems}", "*")
4
4
  end
@@ -209,8 +209,8 @@ class ShouldMatcherTest < Test::Unit::TestCase
209
209
  end
210
210
  end
211
211
 
212
- def run_test
213
- @test_suite.run(@test_result) { |event, name |}
212
+ def run_test_suite
213
+ @test_suite.run(@test_result) { |event, name| }
214
214
  end
215
215
 
216
216
  def setup
@@ -249,19 +249,19 @@ class ShouldMatcherTest < Test::Unit::TestCase
249
249
 
250
250
  should "pass with a passing matcher" do
251
251
  @matcher.fail = false
252
- run_test
252
+ run_test_suite
253
253
  assert_passed @test_result
254
254
  end
255
255
 
256
256
  should "fail with a failing matcher" do
257
257
  @matcher.fail = true
258
- run_test
258
+ run_test_suite
259
259
  assert_failed_with @matcher.failure_message, @test_result
260
260
  end
261
261
 
262
262
  should "provide the subject" do
263
263
  @matcher.fail = false
264
- run_test
264
+ run_test_suite
265
265
  assert_equal 'a subject', @matcher.subject
266
266
  end
267
267
  end
@@ -273,19 +273,19 @@ class ShouldMatcherTest < Test::Unit::TestCase
273
273
 
274
274
  should "pass with a failing matcher" do
275
275
  @matcher.fail = true
276
- run_test
276
+ run_test_suite
277
277
  assert_passed @test_result
278
278
  end
279
279
 
280
280
  should "fail with a passing matcher" do
281
281
  @matcher.fail = false
282
- run_test
282
+ run_test_suite
283
283
  assert_failed_with @matcher.negative_failure_message, @test_result
284
284
  end
285
285
 
286
286
  should "provide the subject" do
287
287
  @matcher.fail = false
288
- run_test
288
+ run_test_suite
289
289
  assert_equal 'a subject', @matcher.subject
290
290
  end
291
291
  end
@@ -26,10 +26,17 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
26
26
  assert_raises(Test::Unit::AssertionFailedError) do
27
27
  assert_same_elements(@a, [3, 3, "def", "abc"])
28
28
  end
29
+ assert_same_elements([@a, "abc"].flatten, ["abc", 3, "def", "abc"])
29
30
  assert_raises(Test::Unit::AssertionFailedError) do
30
31
  assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
31
32
  end
32
33
  end
34
+
35
+ should "only count the number of occurrences once for each unique value" do
36
+ a1 = [@a, "abc"].flatten
37
+ a1.expects(:select).times(3).returns(["abc", "abc"], ["def"], [3])
38
+ assert_same_elements(a1, ["abc", 3, "def", "abc"])
39
+ end
33
40
  end
34
41
 
35
42
  context "a matching matcher" do
@@ -54,19 +61,36 @@ class HelpersTest < Test::Unit::TestCase # :nodoc:
54
61
  end
55
62
 
56
63
  context "when given to assert_rejects" do
57
- setup do
58
- begin
59
- assert_rejects @matcher, 'target'
60
- rescue Test::Unit::AssertionFailedError => @error
64
+ context "and matcher has :does_not_match?" do
65
+ setup do
66
+ begin
67
+ @matcher.stubs(:matches?).returns(false)
68
+ @matcher.stubs(:does_not_match?).returns(true)
69
+ assert_rejects @matcher, 'target'
70
+ rescue Test::Unit::AssertionFailedError => @error
71
+ end
61
72
  end
62
- end
63
73
 
64
- should "fail" do
65
- assert_not_nil @error
74
+ should "pass" do
75
+ assert_nil @error
76
+ end
66
77
  end
67
78
 
68
- should "use the error message from the matcher" do
69
- assert_equal 'big time failure', @error.message
79
+ context "and matcher does not have :does_not_match?" do
80
+ setup do
81
+ begin
82
+ assert_rejects @matcher, 'target'
83
+ rescue Test::Unit::AssertionFailedError => @error
84
+ end
85
+ end
86
+
87
+ should "fail" do
88
+ assert_not_nil @error
89
+ end
90
+
91
+ should "use the error message from the matcher" do
92
+ assert_equal 'big time failure', @error.message
93
+ end
70
94
  end
71
95
  end
72
96
  end
@@ -128,6 +128,15 @@ class ShouldTest < Test::Unit::TestCase # :nodoc:
128
128
  end
129
129
  end
130
130
 
131
+ def test_should_create_a_new_context_even_if_block_is_omitted
132
+ old_verbose, $VERBOSE = $VERBOSE, nil
133
+ assert_nothing_raised do
134
+ Shoulda::Context::Context.new("context without a block", self)
135
+ end
136
+ ensure
137
+ $VERBOSE = old_verbose
138
+ end
139
+
131
140
  def test_should_create_a_nested_context
132
141
  assert_nothing_raised do
133
142
  parent = Shoulda::Context::Context.new("Parent", self) do; end
data/test/test_helper.rb CHANGED
@@ -4,7 +4,7 @@ require 'mocha'
4
4
 
5
5
  shoulda_path = File.join(File.dirname(__FILE__), '..', 'lib')
6
6
  $LOAD_PATH << shoulda_path
7
- require 'shoulda-context'
7
+ require "shoulda/context"
8
8
 
9
9
  Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'fake_rails_root'),
10
10
  File.join("vendor", "{plugins,gems}", "*")
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-context
3
3
  version: !ruby/object:Gem::Version
4
- hash: 299253597
5
- prerelease: true
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta1
11
- version: 1.0.0.beta1
10
+ version: 1.0.0
12
11
  platform: ruby
13
12
  authors:
14
13
  - thoughtbot, inc.
@@ -21,10 +20,53 @@ autorequire:
21
20
  bindir: bin
22
21
  cert_chain: []
23
22
 
24
- date: 2011-01-19 00:00:00 -05:00
25
- default_executable: convert_to_should_syntax
26
- dependencies: []
27
-
23
+ date: 2011-11-02 00:00:00 Z
24
+ dependencies:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ prerelease: false
28
+ requirement: &id001 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ hash: 47
34
+ segments:
35
+ - 0
36
+ - 9
37
+ - 10
38
+ version: 0.9.10
39
+ type: :development
40
+ version_requirements: *id001
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ prerelease: false
44
+ requirement: &id002 !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ type: :development
54
+ version_requirements: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ prerelease: false
58
+ requirement: &id003 !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ hash: 3
64
+ segments:
65
+ - 2
66
+ - 0
67
+ version: "2.0"
68
+ type: :development
69
+ version_requirements: *id003
28
70
  description: Context framework extracted from Shoulda
29
71
  email: support@thoughtbot.com
30
72
  executables:
@@ -50,6 +92,7 @@ files:
50
92
  - lib/shoulda/context/tasks/yaml_to_shoulda.rake
51
93
  - lib/shoulda/context/tasks.rb
52
94
  - lib/shoulda/context/version.rb
95
+ - lib/shoulda/context.rb
53
96
  - lib/shoulda-context.rb
54
97
  - rails/init.rb
55
98
  - test/fake_rails_root/test/shoulda_macros/custom_macro.rb
@@ -61,7 +104,7 @@ files:
61
104
  - test/shoulda/helpers_test.rb
62
105
  - test/shoulda/should_test.rb
63
106
  - test/test_helper.rb
64
- has_rdoc: true
107
+ - init.rb
65
108
  homepage: http://thoughtbot.com/community/
66
109
  licenses: []
67
110
 
@@ -93,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
136
  requirements: []
94
137
 
95
138
  rubyforge_project:
96
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.8.10
97
140
  signing_key:
98
141
  specification_version: 3
99
142
  summary: Context framework extracted from Shoulda