mocha 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -13,11 +13,13 @@ Mocha was harvested from projects at Reevoo[http://www.reevoo.com] by me (James[
13
13
  Install the gem with the following command...
14
14
 
15
15
  $ gem install mocha
16
-
16
+
17
17
  Or install the Rails[http://www.rubyonrails.org] plugin...
18
18
 
19
19
  $ script/plugin install git://github.com/floehopper/mocha.git
20
20
 
21
+ Note that versions 0.9.6 & 0.9.7 of the Rails plugin were broken. As of version 0.9.8, you need to explicitly load Mocha after the test framework e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
22
+
21
23
  Or download Mocha...
22
24
 
23
25
  http://rubyforge.org/frs/?group_id=1917
data/RELEASE CHANGED
@@ -1,4 +1,11 @@
1
- = 0.9.7 ()
1
+ = 0.9.8 (645024765b2d92018efc511652e1174163844e39)
2
+ * Fixed bug "NameError raised when using Mocha as a Rails plug-in" - http://floehopper.lighthouseapp.com/projects/22289/tickets/53. Since 0.9.6 the Rails plugin has been broken. See bug report for details. You will need to explicitly load Mocha *after* the test framework has been loaded, e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
3
+ * Make Mocha::ParameterMatchers#regexp_matches, #includes, #has_value, #has_key more robust. Thanks to Sander Hartlage.
4
+ * Allow passing a block to Mocha::Configuration methods to only change configuration for the duration of the block. Thanks to Dan Manges.
5
+ * Fixed bug "doc generation fails in 0.9.7 gem" - http://floehopper.lighthouseapp.com/projects/22289/tickets/51.
6
+ * Remove rdoc template incorporating google analytics from source control. The file just needs to exist locally and be ignored by source control. This should stop the warning showing up on e.g. RunCodeRun build results.
7
+
8
+ = 0.9.7 (80d816f250dc13aaf856f3f9cbd97ebe9c371839)
2
9
  * Although I had provided a deprecation warning for people using Mocha::Standalone, I had assumed people wouldn't be explicitly loading the mocha/standalone.rb file. It turns out this assumption was incorrect at least in the case of Rspec. This is now fixed.
3
10
 
4
11
  = 0.9.6 (57f8f77d715b7f1d9efee2e1a9438f7905c0006b)
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
  require 'rake/testtask'
4
4
 
5
5
  module Mocha
6
- VERSION = "0.9.7"
6
+ VERSION = "0.9.8"
7
7
  end
8
8
 
9
9
  desc "Run all tests"
@@ -70,7 +70,11 @@ Rake::RDocTask.new('rdoc') do |task|
70
70
  task.main = 'README'
71
71
  task.title = "Mocha #{Mocha::VERSION}"
72
72
  task.rdoc_dir = 'doc'
73
- task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics"))
73
+ template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics.rb"))
74
+ if File.exist?(template)
75
+ puts "*** Using RDoc template incorporating Google Analytics"
76
+ task.template = template
77
+ end
74
78
  task.rdoc_files.include(
75
79
  'README',
76
80
  'RELEASE',
@@ -7,36 +7,39 @@ module Mocha # :nodoc:
7
7
 
8
8
  class << self
9
9
 
10
- # :call-seq: allow(action)
10
+ # :call-seq: allow(action, &block)
11
11
  #
12
12
  # Allow the specified <tt>action</tt> (as a symbol).
13
13
  # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
14
- def allow(action)
15
- configuration[action] = :allow
14
+ # If given a block, the configuration for the action will only be changed for the duration of the block, and will then be restored to the previous value.
15
+ def allow(action, &block)
16
+ change_config action, :allow, &block
16
17
  end
17
18
 
18
19
  def allow?(action) # :nodoc:
19
20
  configuration[action] == :allow
20
21
  end
21
22
 
22
- # :call-seq: warn_when(action)
23
+ # :call-seq: warn_when(action, &block)
23
24
  #
24
25
  # Warn if the specified <tt>action</tt> (as a symbol) is attempted.
25
26
  # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
26
- def warn_when(action)
27
- configuration[action] = :warn
27
+ # If given a block, the configuration for the action will only be changed for the duration of the block, and will then be restored to the previous value.
28
+ def warn_when(action, &block)
29
+ change_config action, :warn, &block
28
30
  end
29
31
 
30
32
  def warn_when?(action) # :nodoc:
31
33
  configuration[action] == :warn
32
34
  end
33
35
 
34
- # :call-seq: prevent(action)
36
+ # :call-seq: prevent(action, &block)
35
37
  #
36
38
  # Raise a StubbingError if the specified <tt>action</tt> (as a symbol) is attempted.
37
39
  # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>.
38
- def prevent(action)
39
- configuration[action] = :prevent
40
+ # If given a block, the configuration for the action will only be changed for the duration of the block, and will then be restored to the previous value.
41
+ def prevent(action, &block)
42
+ change_config action, :prevent, &block
40
43
  end
41
44
 
42
45
  def prevent?(action) # :nodoc:
@@ -52,9 +55,25 @@ module Mocha # :nodoc:
52
55
  def configuration # :nodoc:
53
56
  @configuration ||= DEFAULTS.dup
54
57
  end
58
+
59
+ def change_config(action, new_value, &block) # :nodoc:
60
+ if block_given?
61
+ temporarily_change_config action, new_value, &block
62
+ else
63
+ configuration[action] = new_value
64
+ end
65
+ end
66
+
67
+ def temporarily_change_config(action, new_value, &block) # :nodoc:
68
+ original_value = configuration[action]
69
+ configuration[action] = new_value
70
+ yield
71
+ ensure
72
+ configuration[action] = original_value
73
+ end
55
74
 
56
75
  end
57
76
 
58
77
  end
59
78
 
60
- end
79
+ end
@@ -28,6 +28,7 @@ module Mocha
28
28
 
29
29
  def matches?(available_parameters)
30
30
  parameter = available_parameters.shift
31
+ return false unless parameter.respond_to?(:keys)
31
32
  parameter.keys.any? { |key| @key.to_matcher.matches?([key]) }
32
33
  end
33
34
 
@@ -28,6 +28,7 @@ module Mocha
28
28
 
29
29
  def matches?(available_parameters)
30
30
  parameter = available_parameters.shift
31
+ return false unless parameter.respond_to?(:values)
31
32
  parameter.values.any? { |value| @value.to_matcher.matches?([value]) }
32
33
  end
33
34
 
@@ -26,6 +26,7 @@ module Mocha
26
26
 
27
27
  def matches?(available_parameters)
28
28
  parameter = available_parameters.shift
29
+ return false unless parameter.respond_to?(:include?)
29
30
  return parameter.include?(@item)
30
31
  end
31
32
 
@@ -29,6 +29,7 @@ module Mocha
29
29
 
30
30
  def matches?(available_parameters)
31
31
  parameter = available_parameters.shift
32
+ return false unless parameter.respond_to?(:=~)
32
33
  parameter =~ @regexp
33
34
  end
34
35
 
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), "..", "test_helper")
2
+ require "mocha/configuration"
3
+
4
+ class ConfigurationTest < Test::Unit::TestCase
5
+ def test_allow_temporarily_changes_config_when_given_block
6
+ Mocha::Configuration.warn_when(:stubbing_method_unnecessarily)
7
+ yielded = false
8
+ Mocha::Configuration.allow(:stubbing_method_unnecessarily) do
9
+ yielded = true
10
+ assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
11
+ end
12
+ assert yielded
13
+ assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
14
+ end
15
+
16
+ def test_prevent_temporarily_changes_config_when_given_block
17
+ Mocha::Configuration.allow(:stubbing_method_unnecessarily)
18
+ yielded = false
19
+ Mocha::Configuration.prevent(:stubbing_method_unnecessarily) do
20
+ yielded = true
21
+ assert Mocha::Configuration.prevent?(:stubbing_method_unnecessarily)
22
+ end
23
+ assert yielded
24
+ assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
25
+ end
26
+
27
+ def test_warn_when_temporarily_changes_config_when_given_block
28
+ Mocha::Configuration.allow(:stubbing_method_unnecessarily)
29
+ yielded = false
30
+ Mocha::Configuration.warn_when(:stubbing_method_unnecessarily) do
31
+ yielded = true
32
+ assert Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily)
33
+ end
34
+ assert yielded
35
+ assert Mocha::Configuration.allow?(:stubbing_method_unnecessarily)
36
+ end
37
+ end
38
+
@@ -33,4 +33,23 @@ class HasKeyTest < Test::Unit::TestCase
33
33
  assert !matcher.matches?([{ :key_2 => 2 }])
34
34
  end
35
35
 
36
+ def test_should_not_raise_error_on_empty_arguments
37
+ matcher = has_key(:key)
38
+ assert_nothing_raised { matcher.matches?([]) }
39
+ end
40
+
41
+ def test_should_not_match_on_empty_arguments
42
+ matcher = has_key(:key)
43
+ assert !matcher.matches?([])
44
+ end
45
+
46
+ def test_should_not_raise_error_on_argument_that_does_not_respond_to_keys
47
+ matcher = has_key(:key)
48
+ assert_nothing_raised { matcher.matches?([:key]) }
49
+ end
50
+
51
+ def test_should_not_match_on_argument_that_does_not_respond_to_keys
52
+ matcher = has_key(:key)
53
+ assert !matcher.matches?([:key])
54
+ end
36
55
  end
@@ -34,4 +34,24 @@ class HasValueTest < Test::Unit::TestCase
34
34
  assert !matcher.matches?([{ :key_2 => 'value_2' }])
35
35
  end
36
36
 
37
+ def test_should_not_raise_error_on_empty_arguments
38
+ matcher = has_value('value_1')
39
+ assert_nothing_raised { matcher.matches?([]) }
40
+ end
41
+
42
+ def test_should_not_match_empty_arguments
43
+ matcher = has_value('value_1')
44
+ assert !matcher.matches?([])
45
+ end
46
+
47
+ def test_should_not_raise_error_on_argument_that_does_not_respond_to_values
48
+ matcher = has_value('value_1')
49
+ assert_nothing_raised { matcher.matches?(['value_1']) }
50
+ end
51
+
52
+ def test_should_not_match_on_argument_that_does_not_respond_to_values
53
+ matcher = has_value('value_1')
54
+ assert !matcher.matches?(['value_1'])
55
+ end
56
+
37
57
  end
@@ -21,5 +21,24 @@ class IncludesTest < Test::Unit::TestCase
21
21
  matcher = includes(:x)
22
22
  assert_equal "includes(:x)", matcher.mocha_inspect
23
23
  end
24
-
24
+
25
+ def test_should_not_raise_error_on_emtpy_arguments
26
+ matcher = includes(:x)
27
+ assert_nothing_raised { matcher.matches?([]) }
28
+ end
29
+
30
+ def test_should_not_match_on_empty_arguments
31
+ matcher = includes(:x)
32
+ assert !matcher.matches?([])
33
+ end
34
+
35
+ def test_should_not_raise_error_on_argument_that_does_not_respond_to_include
36
+ matcher = includes(:x)
37
+ assert_nothing_raised { matcher.matches?([:x]) }
38
+ end
39
+
40
+ def test_should_not_match_on_argument_that_does_not_respond_to_include
41
+ matcher = includes(:x)
42
+ assert !matcher.matches?([:x])
43
+ end
25
44
  end
@@ -22,4 +22,25 @@ class RegexpMatchesTest < Test::Unit::TestCase
22
22
  assert_equal "regexp_matches(/oo/)", matcher.mocha_inspect
23
23
  end
24
24
 
25
+ def test_should_not_raise_error_on_empty_arguments
26
+ matcher = regexp_matches(/oo/)
27
+ assert_nothing_raised { matcher.matches?([]) }
28
+ end
29
+
30
+ def test_should_not_match_on_empty_arguments
31
+ matcher = regexp_matches(/oo/)
32
+ assert !matcher.matches?([])
33
+ end
34
+
35
+ def test_should_not_raise_error_on_argument_that_does_not_respond_to_equals_tilde
36
+ object_not_responding_to_equals_tilde = Class.new { undef =~ }.new
37
+ matcher = regexp_matches(/oo/)
38
+ assert_nothing_raised { matcher.matches?([object_not_responding_to_equals_tilde]) }
39
+ end
40
+
41
+ def test_should_not_match_on_argument_that_does_not_respond_to_equals_tilde
42
+ object_not_responding_to_equals_tilde = Class.new { undef =~ }.new
43
+ matcher = regexp_matches(/oo/)
44
+ assert !matcher.matches?([object_not_responding_to_equals_tilde])
45
+ end
25
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-01 00:00:00 +01:00
12
+ date: 2009-09-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.
25
+ description: " Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.\n"
26
26
  email: mocha-developer@googlegroups.com
27
27
  executables: []
28
28
 
@@ -155,6 +155,7 @@ files:
155
155
  - test/unit/central_test.rb
156
156
  - test/unit/change_state_side_effect_test.rb
157
157
  - test/unit/class_method_test.rb
158
+ - test/unit/configuration_test.rb
158
159
  - test/unit/date_time_inspect_test.rb
159
160
  - test/unit/exception_raiser_test.rb
160
161
  - test/unit/expectation_list_test.rb
@@ -204,6 +205,8 @@ files:
204
205
  - RELEASE
205
206
  has_rdoc: true
206
207
  homepage: http://mocha.rubyforge.org
208
+ licenses: []
209
+
207
210
  post_install_message:
208
211
  rdoc_options:
209
212
  - --title
@@ -228,9 +231,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
231
  requirements: []
229
232
 
230
233
  rubyforge_project: mocha
231
- rubygems_version: 1.3.1
234
+ rubygems_version: 1.3.4
232
235
  signing_key:
233
- specification_version: 2
236
+ specification_version: 3
234
237
  summary: Mocking and stubbing library
235
238
  test_files: []
236
239