dchelimsky-rspec 1.1.11.3 → 1.1.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/History.txt +2 -1
  2. data/Manifest.txt +6 -5
  3. data/TODO.txt +10 -2
  4. data/examples/failing/{failure_in_teardown.rb → failure_in_after.rb} +1 -1
  5. data/examples/failing/{failure_in_setup.rb → failure_in_before.rb} +1 -1
  6. data/features/example_groups/autogenerated_docstrings.feature +4 -4
  7. data/features/example_groups/nested_groups.feature +1 -1
  8. data/features/support/env.rb +1 -0
  9. data/lib/adapters/mock_frameworks/flexmock.rb +1 -1
  10. data/lib/adapters/mock_frameworks/mocha.rb +1 -1
  11. data/lib/adapters/mock_frameworks/rr.rb +1 -1
  12. data/lib/adapters/mock_frameworks/rspec.rb +1 -1
  13. data/lib/spec/example.rb +0 -1
  14. data/lib/spec/example/example_group_methods.rb +29 -25
  15. data/lib/spec/expectations.rb +0 -1
  16. data/lib/spec/matchers.rb +1 -0
  17. data/lib/spec/matchers/equal.rb +1 -1
  18. data/lib/spec/matchers/respond_to.rb +33 -8
  19. data/lib/spec/{expectations → matchers}/wrap_expectation.rb +0 -1
  20. data/lib/spec/mocks/message_expectation.rb +7 -2
  21. data/lib/spec/mocks/proxy.rb +1 -1
  22. data/lib/spec/runner.rb +13 -2
  23. data/lib/spec/runner/backtrace_tweaker.rb +5 -3
  24. data/lib/spec/{example → runner}/configuration.rb +3 -3
  25. data/lib/spec/runner/formatter/html_formatter.rb +14 -11
  26. data/lib/spec/runner/options.rb +12 -2
  27. data/lib/spec/runner/spec_parser.rb +3 -2
  28. data/lib/spec/version.rb +1 -1
  29. data/rspec.gemspec +4 -4
  30. data/spec/spec/example/example_group_methods_spec.rb +9 -9
  31. data/spec/spec/example/example_methods_spec.rb +15 -13
  32. data/spec/spec/matchers/description_generation_spec.rb +1 -1
  33. data/spec/spec/matchers/respond_to_spec.rb +71 -9
  34. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
  35. data/spec/spec/runner/configuration_spec.rb +290 -0
  36. data/spec/spec/runner/formatter/base_formatter_spec.rb +13 -102
  37. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +33 -24
  38. data/spec/spec/runner/formatter/html_formatter_spec.rb +6 -1
  39. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +7 -2
  40. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -30
  41. data/spec/spec/runner/spec_parser_spec.rb +1 -1
  42. data/spec/spec_helper.rb +1 -1
  43. metadata +9 -8
  44. data/spec/spec/example/configuration_spec.rb +0 -296
data/History.txt CHANGED
@@ -23,7 +23,7 @@
23
23
  * SpecParser can't handle backtrace paths with colons (John-Mason P. Shackelford). Closes #505.
24
24
  * html formatter (and subsequently the textmate formatter) header fills in completely when running a single example
25
25
 
26
- * 7 bug fixes
26
+ * 8 bug fixes
27
27
 
28
28
  * fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn)
29
29
  * only try to load Test::Unit if Test::Unit is defined (not just Test)
@@ -32,6 +32,7 @@
32
32
  * Removed incorrect -S flag on autospec commands. Added explicit spec command for ruby to run, guarantee running rspec (raggi). Closes #507.
33
33
  * Check whether test/unit has really been loaded before calling a method it defines (Brian Donovan). Closes #503.
34
34
  * Fix spec_path for shared groups (Zach Dennis). Closes #615.
35
+ * stubbed message expectation not verified if it has been called *before* the expectation (Matthias Hennemeyer). Closes #637.
35
36
 
36
37
  === Version 1.1.11 / 2008-10-24
37
38
 
data/Manifest.txt CHANGED
@@ -10,8 +10,8 @@ bin/spec
10
10
  examples/failing/README.txt
11
11
  examples/failing/diffing_spec.rb
12
12
  examples/failing/failing_autogenerated_docstrings_example.rb
13
- examples/failing/failure_in_setup.rb
14
- examples/failing/failure_in_teardown.rb
13
+ examples/failing/failure_in_after.rb
14
+ examples/failing/failure_in_before.rb
15
15
  examples/failing/mocking_example.rb
16
16
  examples/failing/mocking_with_flexmock.rb
17
17
  examples/failing/mocking_with_mocha.rb
@@ -78,7 +78,6 @@ lib/spec/dsl.rb
78
78
  lib/spec/dsl/main.rb
79
79
  lib/spec/example.rb
80
80
  lib/spec/example/before_and_after_hooks.rb
81
- lib/spec/example/configuration.rb
82
81
  lib/spec/example/errors.rb
83
82
  lib/spec/example/example_group.rb
84
83
  lib/spec/example/example_group_factory.rb
@@ -95,7 +94,6 @@ lib/spec/expectations/extensions.rb
95
94
  lib/spec/expectations/extensions/object.rb
96
95
  lib/spec/expectations/extensions/string_and_symbol.rb
97
96
  lib/spec/expectations/handler.rb
98
- lib/spec/expectations/wrap_expectation.rb
99
97
  lib/spec/interop/test.rb
100
98
  lib/spec/interop/test/unit/autorunner.rb
101
99
  lib/spec/interop/test/unit/testcase.rb
@@ -123,6 +121,7 @@ lib/spec/matchers/respond_to.rb
123
121
  lib/spec/matchers/satisfy.rb
124
122
  lib/spec/matchers/simple_matcher.rb
125
123
  lib/spec/matchers/throw_symbol.rb
124
+ lib/spec/matchers/wrap_expectation.rb
126
125
  lib/spec/mocks.rb
127
126
  lib/spec/mocks/argument_constraints.rb
128
127
  lib/spec/mocks/argument_expectation.rb
@@ -144,6 +143,7 @@ lib/spec/runner.rb
144
143
  lib/spec/runner/backtrace_tweaker.rb
145
144
  lib/spec/runner/class_and_arguments_parser.rb
146
145
  lib/spec/runner/command_line.rb
146
+ lib/spec/runner/configuration.rb
147
147
  lib/spec/runner/drb_command_line.rb
148
148
  lib/spec/runner/example_group_runner.rb
149
149
  lib/spec/runner/formatter/base_formatter.rb
@@ -208,7 +208,6 @@ spec/rspec_suite.rb
208
208
  spec/ruby_forker.rb
209
209
  spec/spec.opts
210
210
  spec/spec/dsl/main_spec.rb
211
- spec/spec/example/configuration_spec.rb
212
211
  spec/spec/example/example_group_class_definition_spec.rb
213
212
  spec/spec/example/example_group_factory_spec.rb
214
213
  spec/spec/example/example_group_methods_spec.rb
@@ -290,10 +289,12 @@ spec/spec/mocks/passing_mock_argument_constraints_spec.rb
290
289
  spec/spec/mocks/precise_counts_spec.rb
291
290
  spec/spec/mocks/record_messages_spec.rb
292
291
  spec/spec/mocks/stub_spec.rb
292
+ spec/spec/mocks/stubbed_message_expectations_spec.rb
293
293
  spec/spec/mocks/twice_counts_spec.rb
294
294
  spec/spec/package/bin_spec_spec.rb
295
295
  spec/spec/runner/class_and_argument_parser_spec.rb
296
296
  spec/spec/runner/command_line_spec.rb
297
+ spec/spec/runner/configuration_spec.rb
297
298
  spec/spec/runner/drb_command_line_spec.rb
298
299
  spec/spec/runner/empty_file.txt
299
300
  spec/spec/runner/examples.txt
data/TODO.txt CHANGED
@@ -1,10 +1,18 @@
1
+ == Refactoring
2
+
3
+ Refactoring for 1.2.0
4
+
5
+ * eliminate dependency from Spec::Example to Spec::Runner
6
+ ** global predictate matchers should be stored in run_options
7
+ * eliminate dependency on global options and configuration
8
+ ** the only place they should exist is in the Runner, which should manage them
9
+
1
10
  == Future
2
11
 
3
12
  * do SOMETHING with the website
4
13
  * extract spec/story to rspec-stories (new gem)
5
- * remove the ruby engine adapter unless Rubinius team plans to use it
6
14
  * rename top level namespace to Rspec and commands to 'rspec' and 'autorspec'
7
15
  * continue to support Spec 'spec' and 'autospec' as aliases for a reasonable time
8
16
  * separate the underlying framework from the DSL
9
17
  * be able to do everything with classes and methods
10
- * tweak raise_error rdoc to show only one arg
18
+ * tweak raise_error rdoc to show only one arg
@@ -1,6 +1,6 @@
1
1
  describe "This example" do
2
2
 
3
- it "should be listed as failing in teardown" do
3
+ it "should be listed as failing in after" do
4
4
  end
5
5
 
6
6
  after(:each) do
@@ -4,7 +4,7 @@ describe "This example" do
4
4
  NonExistentClass.new
5
5
  end
6
6
 
7
- it "should be listed as failing in setup" do
7
+ it "should be listed as failing in each" do
8
8
  end
9
9
 
10
10
  end
@@ -12,7 +12,7 @@ Feature: autogenerated docstrings
12
12
  Then the stdout should match /should equal 5/
13
13
  And the stdout should match /should be < 5/
14
14
  And the stdout should match /should include "a"/
15
- And the stdout should match /should respond to \[:size\]/
15
+ And the stdout should match /should respond to #size/
16
16
 
17
17
  Scenario: run failing examples with ruby
18
18
  Given the file ../../examples/failing/failing_autogenerated_docstrings_example.rb
@@ -22,7 +22,7 @@ Feature: autogenerated docstrings
22
22
  Then the stdout should match /should equal 2/
23
23
  And the stdout should match /should be > 5/
24
24
  And the stdout should match /should include "b"/
25
- And the stdout should match /should not respond to \[:size\]/
25
+ And the stdout should match /should not respond to #size/
26
26
 
27
27
  Scenario: run passing examples with spec
28
28
  Given the file ../../examples/passing/autogenerated_docstrings_example.rb
@@ -32,7 +32,7 @@ Feature: autogenerated docstrings
32
32
  Then the stdout should match /should equal 5/
33
33
  And the stdout should match /should be < 5/
34
34
  And the stdout should match /should include "a"/
35
- And the stdout should match /should respond to \[:size\]/
35
+ And the stdout should match /should respond to #size/
36
36
 
37
37
  Scenario: run failing examples with spec
38
38
  Given the file ../../examples/failing/failing_autogenerated_docstrings_example.rb
@@ -42,4 +42,4 @@ Feature: autogenerated docstrings
42
42
  Then the stdout should match /should equal 2/
43
43
  And the stdout should match /should be > 5/
44
44
  And the stdout should match /should include "b"/
45
- And the stdout should match /should not respond to \[:size\]/
45
+ And the stdout should match /should not respond to #size/
@@ -10,7 +10,7 @@ Feature: Nested example groups
10
10
  Then the stdout should match /Stack \(empty\)/
11
11
  And the stdout should match /Stack \(full\)/
12
12
 
13
- Scenario: Run with ruby
13
+ Scenario: Run with spec
14
14
  Given the file ../../examples/passing/stack_spec_with_nested_example_groups.rb
15
15
  When I run it with the spec script -fs
16
16
  Then the stdout should match /Stack \(empty\)/
@@ -2,6 +2,7 @@ require 'tempfile'
2
2
  require File.dirname(__FILE__) + '/../../spec/ruby_forker'
3
3
  require File.dirname(__FILE__) + '/matchers/smart_match'
4
4
 
5
+ $:.push File.join(File.dirname(__FILE__), "/../../lib")
5
6
  require 'spec/expectations'
6
7
  require 'spec/matchers'
7
8
 
@@ -6,7 +6,7 @@
6
6
  require 'flexmock/rspec'
7
7
 
8
8
  module Spec
9
- module Plugins
9
+ module Adapters
10
10
  module MockFramework
11
11
  include FlexMock::MockContainer
12
12
  def setup_mocks_for_rspec
@@ -2,7 +2,7 @@ require 'mocha/standalone'
2
2
  require 'mocha/object'
3
3
 
4
4
  module Spec
5
- module Plugins
5
+ module Adapters
6
6
  module MockFramework
7
7
  include Mocha::Standalone
8
8
  def setup_mocks_for_rspec
@@ -4,7 +4,7 @@ patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
4
4
  patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
5
5
 
6
6
  module Spec
7
- module Plugins
7
+ module Adapters
8
8
  module MockFramework
9
9
  include RR::Extensions::InstanceMethods
10
10
  def setup_mocks_for_rspec
@@ -3,7 +3,7 @@ require 'spec/mocks/framework'
3
3
  require 'spec/mocks/extensions'
4
4
 
5
5
  module Spec
6
- module Plugins
6
+ module Adapters
7
7
  module MockFramework
8
8
  include Spec::Mocks::ExampleMethods
9
9
  def setup_mocks_for_rspec
data/lib/spec/example.rb CHANGED
@@ -182,6 +182,5 @@ require 'spec/example/example_group'
182
182
  require 'spec/example/shared_example_group'
183
183
  require 'spec/example/example_group_factory'
184
184
  require 'spec/example/errors'
185
- require 'spec/example/configuration'
186
185
  require 'spec/example/example_matcher'
187
186
 
@@ -2,23 +2,23 @@ module Spec
2
2
  module Example
3
3
 
4
4
  module ExampleGroupMethods
5
- include Spec::Example::BeforeAndAfterHooks
6
-
7
- def self.matcher_class
8
- @matcher_class
9
- end
10
-
11
- def self.matcher_class=(matcher_class)
12
- @matcher_class = matcher_class
13
- end
5
+ class << self
6
+ attr_accessor :matcher_class
14
7
 
15
- def self.description_text(*args)
16
- args.inject("") do |description, arg|
17
- description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
18
- description << arg.to_s
8
+ def description_text(*args)
9
+ args.inject("") do |description, arg|
10
+ description << " " unless (description == "" || arg.to_s =~ /^(\s|\.|#)/)
11
+ description << arg.to_s
12
+ end
13
+ end
14
+
15
+ def example_group_creation_listeners
16
+ @example_group_creation_listeners ||= []
19
17
  end
20
18
  end
21
19
 
20
+ include Spec::Example::BeforeAndAfterHooks
21
+
22
22
  attr_reader :description_options, :spec_path
23
23
  alias :options :description_options
24
24
 
@@ -42,8 +42,13 @@ WARNING
42
42
 
43
43
  def inherited(klass)
44
44
  super
45
- Spec::Runner.options.add_example_group klass
46
- Spec::Runner.register_at_exit_hook
45
+ register_example_group(klass)
46
+ end
47
+
48
+ def register_example_group(klass)
49
+ ExampleGroupMethods.example_group_creation_listeners.each do |l|
50
+ l.register_example_group(klass)
51
+ end
47
52
  end
48
53
 
49
54
  # Makes the describe/it syntax available from a class. For example:
@@ -103,7 +108,6 @@ WARNING
103
108
  end
104
109
 
105
110
  # Use this to pull in examples from shared example groups.
106
- # See Spec::Runner for information about shared example groups.
107
111
  def it_should_behave_like(*shared_example_groups)
108
112
  shared_example_groups.each do |group|
109
113
  include_shared_example_group(group)
@@ -118,7 +122,7 @@ WARNING
118
122
  # a predicate on your class. RSpec provides a couple of these
119
123
  # out of the box:
120
124
  #
121
- # exist (or state expectations)
125
+ # exist (for state expectations)
122
126
  # File.should exist("path/to/file")
123
127
  #
124
128
  # an_instance_of (for mock argument constraints)
@@ -167,8 +171,8 @@ WARNING
167
171
  return true if examples.empty?
168
172
  return dry_run(examples, run_options) if run_options.dry_run?
169
173
 
170
- plugin_mock_framework
171
- define_methods_from_predicate_matchers
174
+ plugin_mock_framework(run_options)
175
+ define_methods_from_predicate_matchers(run_options)
172
176
 
173
177
  success, before_all_instance_variables = run_before_all(run_options)
174
178
  success, after_all_instance_variables = execute_examples(success, before_all_instance_variables, examples, run_options)
@@ -331,19 +335,19 @@ WARNING
331
335
  klass.kind_of?(ExampleGroupMethods) && klass.included_modules.include?(ExampleMethods)
332
336
  end
333
337
 
334
- def plugin_mock_framework
335
- case mock_framework = Spec::Runner.configuration.mock_framework
338
+ def plugin_mock_framework(run_options)
339
+ case mock_framework = run_options.mock_framework
336
340
  when Module
337
341
  include mock_framework
338
342
  else
339
- require Spec::Runner.configuration.mock_framework
340
- include Spec::Plugins::MockFramework
343
+ require mock_framework
344
+ include Spec::Adapters::MockFramework
341
345
  end
342
346
  end
343
347
 
344
- def define_methods_from_predicate_matchers # :nodoc:
348
+ def define_methods_from_predicate_matchers(run_options) # :nodoc:
345
349
  all_predicate_matchers = predicate_matchers.merge(
346
- Spec::Runner.configuration.predicate_matchers
350
+ run_options.predicate_matchers
347
351
  )
348
352
  all_predicate_matchers.each_pair do |matcher_method, method_on_object|
349
353
  define_method matcher_method do |*args|
@@ -2,7 +2,6 @@ require 'spec/matchers'
2
2
  require 'spec/expectations/errors'
3
3
  require 'spec/expectations/extensions'
4
4
  require 'spec/expectations/handler'
5
- require 'spec/expectations/wrap_expectation'
6
5
 
7
6
  module Spec
8
7
 
data/lib/spec/matchers.rb CHANGED
@@ -18,6 +18,7 @@ require 'spec/matchers/raise_error'
18
18
  require 'spec/matchers/respond_to'
19
19
  require 'spec/matchers/satisfy'
20
20
  require 'spec/matchers/throw_symbol'
21
+ require 'spec/matchers/wrap_expectation'
21
22
 
22
23
  module Spec
23
24
 
@@ -5,7 +5,7 @@ module Spec
5
5
  # should equal(expected)
6
6
  # should_not equal(expected)
7
7
  #
8
- # Passes if given and expected are the same object (object identity).
8
+ # Passes if actual and expected are the same object (object identity).
9
9
  #
10
10
  # See http://www.ruby-doc.org/core/classes/Object.html#M001057 for more information about equality in Ruby.
11
11
  #
@@ -4,30 +4,55 @@ module Spec
4
4
  class RespondTo #:nodoc:
5
5
  def initialize(*names)
6
6
  @names = names
7
+ @expected_arity = nil
7
8
  @names_not_responded_to = []
8
9
  end
9
10
 
10
- def matches?(given)
11
- @given = given
11
+ def matches?(actual)
12
+ @actual = actual
12
13
  @names.each do |name|
13
- unless given.respond_to?(name)
14
- @names_not_responded_to << name
15
- end
14
+ @names_not_responded_to << name unless actual.respond_to?(name) && matches_arity?(actual, name)
16
15
  end
17
16
  return @names_not_responded_to.empty?
18
17
  end
19
18
 
20
19
  def failure_message
21
- "expected #{@given.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
20
+ "expected #{@actual.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}#{with_arity}"
22
21
  end
23
22
 
24
23
  def negative_failure_message
25
- "expected #{@given.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
24
+ "expected #{@actual.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
26
25
  end
27
26
 
28
27
  def description
29
28
  # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
30
- "respond to #{@names.inspect}"
29
+ "respond to #{pp_names}#{with_arity}"
30
+ end
31
+
32
+ def with(n)
33
+ @expected_arity = n
34
+ self
35
+ end
36
+
37
+ def argument
38
+ self
39
+ end
40
+ alias :arguments :argument
41
+
42
+ private
43
+
44
+ def matches_arity?(actual, name)
45
+ @expected_arity.nil?? true :
46
+ @expected_arity == actual.method(name).arity
47
+ end
48
+
49
+ def with_arity
50
+ @expected_arity.nil?? "" :
51
+ " with #{@expected_arity} argument#{@expected_arity == 1 ? '' : 's'}"
52
+ end
53
+
54
+ def pp_names
55
+ @names.length == 1 ? "##{@names.first}" : @names.inspect
31
56
  end
32
57
  end
33
58
 
@@ -1,6 +1,5 @@
1
1
  module Spec
2
2
  module Matchers
3
-
4
3
  # wraps an expectation in a block that will return true if the
5
4
  # expectation passes and false if it fails (without bubbling up
6
5
  # the failure).
@@ -32,6 +32,7 @@ module Spec
32
32
  child.expected_from = expected_from
33
33
  child.method_block = method_block
34
34
  child.expected_received_count = expected_received_count
35
+ child.clear_actual_received_count!
35
36
  new_gen = error_generator.clone
36
37
  new_gen.opts = opts
37
38
  child.error_generator = new_gen
@@ -87,7 +88,7 @@ module Spec
87
88
  @args_to_yield << args
88
89
  self
89
90
  end
90
-
91
+
91
92
  def matches(sym, args)
92
93
  @sym == sym and @args_expectation.args_match?(args)
93
94
  end
@@ -191,7 +192,7 @@ module Spec
191
192
  @sym == sym and not @args_expectation.args_match?(args)
192
193
  end
193
194
 
194
- def verify_messages_received
195
+ def verify_messages_received
195
196
  return if expected_messages_received? || failed_fast?
196
197
 
197
198
  generate_error
@@ -309,6 +310,10 @@ module Spec
309
310
  2
310
311
  end
311
312
  end
313
+
314
+ def clear_actual_received_count!
315
+ @actual_received_count = 0
316
+ end
312
317
 
313
318
  end
314
319