rspec 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.add_exception("spec/interop/test/unit/resources")
3
+ at.add_exception("spec/spec/runner/drb_command_line_spec.rb")
4
+ end
5
+
@@ -0,0 +1,15 @@
1
+ pkg
2
+ doc
3
+ coverage*
4
+ tmtags
5
+ .DS_Store
6
+ .emacs-project
7
+ *~
8
+ email.txt
9
+ tmp
10
+ *.sw?
11
+ spec/spec_files.txt
12
+ tags
13
+
14
+ # rubinius byte code files
15
+ *.rbc
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem "flexmock", '>= 0.8.6'
6
+ gem "heckle", '>= 1.4.2'
7
+ gem "hoe", '>= 2.0'
8
+ gem "nokogiri", '>= 1.2.3'
9
+ gem "mocha", '>= 0.9.5'
10
+ gem "rake", '>= 0.8.4'
11
+ gem "rcov", '>= 0.9.7.1'
12
+ gem "rr", '>= 0.10.0'
13
+ gem "ruby-debug", :platforms => :mri_18
14
+ gem "ruby-debug19", "~> 0.11.6", :platforms => :mri_19
15
+ gem "test-unit", "1.2.3", :platforms => :mri_19
16
+
17
+ case RUBY_VERSION
18
+ when '1.9.1'; gem 'ruby-debug-base19', '0.11.23'
19
+ when '1.9.2'; gem 'ruby-debug-base19', '0.11.24'
20
+ end
@@ -1,3 +1,17 @@
1
+ === Version 1.3.2 / 2011-04-11
2
+
3
+ * Enhancements
4
+ * Raise a meaningful error when an argument-scoped stub is called with the
5
+ wrong args (Alexey)
6
+ * Dev: ignore .rbc files (Myron Marston)
7
+
8
+ * Bug fixes
9
+ * Fix regression in which an expectation should return the value from a
10
+ previously defined stub of the same method (Tom Stuart)
11
+ * Support heckling class methods (Dan Kubb)
12
+ * Only try to pass messages to the superclass if the superclass responds to
13
+ the method (Andrew Selder)
14
+
1
15
  === Version 1.3.1 / 2010-10-09
2
16
 
3
17
  * enhancements
@@ -1,12 +1,15 @@
1
1
  == RSpec
2
2
 
3
- http://rspec.info
4
-
5
3
  Behaviour Driven Development for Ruby
6
4
 
7
- This is the repository for rspec-1.x. If you're looking
8
- for rspec-2 (and if you're not, what are you waiting for?),
9
- see http://github.com/rspec/rspec
5
+ This is the repository for rspec-1.x. For more information, please
6
+ see http://rspec.info.
7
+
8
+ If you're looking for rspec-2 (and if you're not, what are you waiting for?),
9
+ see:
10
+
11
+ * http://relishapp.com/rspec
12
+ * http://github.com/rspec/rspec
10
13
 
11
14
  == Install
12
15
 
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
- # -*- ruby -*-
2
- gem 'hoe', '>=2.0.0'
3
- require 'hoe'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
4
3
 
5
4
  $:.unshift 'lib'
6
5
 
@@ -8,38 +7,6 @@ require 'spec/version'
8
7
  require 'spec/rake/spectask'
9
8
  require 'spec/ruby'
10
9
 
11
- Hoe.spec 'rspec' do
12
- self.version = Spec::VERSION::STRING
13
- self.summary = Spec::VERSION::SUMMARY
14
- self.description = "Behaviour Driven Development for Ruby."
15
- self.rubyforge_name = 'rspec'
16
- self.developer('RSpec Development Team', 'rspec-devel@rubyforge.org')
17
- self.extra_dev_deps << ["cucumber",">=0.3"] << ["fakefs",">=0.2.1"] << ["syntax",">=1.0"] << ["diff-lcs",">=1.1.2"]
18
- self.extra_dev_deps << ["heckle",">=1.4.3"] unless Spec::Ruby.version >= "1.9"
19
- self.remote_rdoc_dir = "rspec/#{Spec::VERSION::STRING}"
20
- self.rspec_options = ['--options', 'spec/spec.opts']
21
- self.history_file = 'History.rdoc'
22
- self.readme_file = 'README.rdoc'
23
- self.post_install_message = <<-POST_INSTALL_MESSAGE
24
- #{'*'*50}
25
-
26
- Thank you for installing rspec-#{Spec::VERSION::STRING}
27
-
28
- Please be sure to read History.rdoc and Upgrade.rdoc
29
- for useful information about this release.
30
-
31
- #{'*'*50}
32
- POST_INSTALL_MESSAGE
33
- end
34
-
35
- ['audit','test','test_deps','default','post_blog'].each do |task|
36
- Rake.application.instance_variable_get('@tasks').delete(task)
37
- end
38
-
39
- task :post_blog do
40
- # no-op
41
- end
42
-
43
10
  # Some of the tasks are in separate files since they are also part of the website documentation
44
11
  load 'resources/rake/examples.rake'
45
12
  load 'resources/rake/examples_with_rcov.rake'
@@ -50,15 +17,19 @@ task :cleanup_rcov_files do
50
17
  rm_rf 'coverage.data'
51
18
  end
52
19
 
53
-
54
20
  if RUBY_VERSION =~ /^1.8/
55
21
  task :default => [:cleanup_rcov_files, :features, :verify_rcov]
56
22
  else
57
23
  task :default => [:spec, :features]
58
24
  end
59
25
 
60
- namespace :spec do
26
+ desc "Run all specs"
27
+ Spec::Rake::SpecTask.new(:spec) do |t|
28
+ t.spec_files = FileList['spec/**/*_spec.rb']
29
+ t.spec_opts = ['--options', 'spec/spec.opts']
30
+ end
61
31
 
32
+ namespace :spec do
62
33
  desc "Run all specs with rcov"
63
34
  Spec::Rake::SpecTask.new(:rcov) do |t|
64
35
  t.spec_files = FileList['spec/**/*_spec.rb']
@@ -121,9 +92,6 @@ task :todo do
121
92
  egrep /(FIXME|TODO|TBD)/
122
93
  end
123
94
 
124
- desc "verify_committed, verify_rcov, post_news, release"
125
- task :complete_release => [:verify_committed, :verify_rcov, :post_news, :release]
126
-
127
95
  desc "Verifies that there is no uncommitted code"
128
96
  task :verify_committed do
129
97
  IO.popen('git status') do |io|
@@ -133,13 +101,6 @@ task :verify_committed do
133
101
  end
134
102
  end
135
103
 
136
- namespace :update do
137
- desc "update the manifest"
138
- task :manifest do
139
- system %q[touch Manifest.txt; rake check_manifest | grep -v "(in " | patch]
140
- end
141
- end
142
-
143
104
  task :clobber => :clobber_tmp
144
105
 
145
106
  task :clobber_tmp do
@@ -0,0 +1,4 @@
1
+ context 'foo' do
2
+ subject { [] }
3
+ its(:size) { should == 1 }
4
+ end
@@ -0,0 +1,39 @@
1
+ Feature: conditional exclusion of example groups
2
+
3
+ Example groups can be excluded from a run by matching the value of the
4
+ --exclude argument against options passed to an example group. The value
5
+ can be a key or a key:value pair (separated by a ":").
6
+
7
+ Scenario: exclusion using explicit value
8
+ Given the following spec:
9
+ """
10
+ describe "This should run" do
11
+ it { 5.should == 5 }
12
+ end
13
+
14
+ describe "This should not run", :slow => true do
15
+ it { 1_000_000.times { 5.should == 5 } }
16
+ end
17
+ """
18
+ When I run it with the spec command --format specdoc --exclude slow:true
19
+ Then the exit code should be 0
20
+ And the stdout should match "1 example, 0 failures"
21
+ And the stdout should match /This should run$/m
22
+ But the stdout should not match "This should not run"
23
+
24
+ Scenario: exclusion using default value (true)
25
+ Given the following spec:
26
+ """
27
+ describe "This should run" do
28
+ it { 5.should == 5 }
29
+ end
30
+
31
+ describe "This should not run", :slow => true do
32
+ it { 1_000_000.times { 5.should == 5 } }
33
+ end
34
+ """
35
+ When I run it with the spec command --format specdoc --exclude slow
36
+ Then the exit code should be 0
37
+ And the stdout should match "1 example, 0 failures"
38
+ And the stdout should match /This should run$/m
39
+ But the stdout should not match "This should not run"
@@ -0,0 +1,56 @@
1
+ Feature: heckle a class
2
+
3
+ As an RSpec user who wants to verify that
4
+ my specs cover what I think it covers
5
+ I want to heckle a class
6
+
7
+ Scenario: Heckle finds problems
8
+ Given a file named "heckle_fail_spec.rb" with:
9
+ """
10
+ class Thing
11
+ def a_or_b
12
+ if true
13
+ "a"
14
+ else
15
+ "b"
16
+ end
17
+ end
18
+ end
19
+
20
+ describe Thing do
21
+ it "returns a for true" do
22
+ Thing.new.a_or_b.should == "a"
23
+ end
24
+ end
25
+ """
26
+ When I run "spec heckle_fail_spec.rb --heckle Thing"
27
+ Then the stdout should match "The following mutations didn't cause test failures:"
28
+ But the stdout should not match "FAILED"
29
+
30
+ Scenario: Heckle does not find a problem
31
+ Given a file named "heckle_success_spec.rb" with:
32
+ """
33
+ class Thing
34
+ def a_or_b(key)
35
+ if key
36
+ "a"
37
+ else
38
+ "b"
39
+ end
40
+ end
41
+ end
42
+
43
+ describe Thing do
44
+ it "returns a for true" do
45
+ Thing.new.a_or_b(true).should == "a"
46
+ end
47
+
48
+ it "returns b for false" do
49
+ Thing.new.a_or_b(false).should == "b"
50
+ end
51
+ end
52
+ """
53
+ When I run "spec heckle_success_spec.rb --heckle Thing"
54
+ Then the stdout should match "No mutants survived"
55
+ But the stdout should not match "FAILED"
56
+
@@ -25,6 +25,6 @@ Feature: custom formatters
25
25
  end
26
26
  """
27
27
 
28
- When I run "spec simple_example_spec.rb --require custom_formatter.rb --format CustomFormatter"
28
+ When I run "spec simple_example_spec.rb --require ./custom_formatter.rb --format CustomFormatter"
29
29
  Then the exit code should be 0
30
30
  And the stdout should include "example: my example"
@@ -35,4 +35,3 @@ Feature: define matcher outside rspec
35
35
  When I run "ruby test_multiples.rb"
36
36
  Then the exit code should be 256
37
37
  And the stdout should include "expected 9 to be a multiple of 4"
38
- And the stdout should include "2 tests, 0 assertions, 1 failures, 0 errors"
@@ -20,7 +20,7 @@ Feature: match unless raises
20
20
  Scenario: passing examples
21
21
  Given a file named "match_unless_raises_spec.rb" with:
22
22
  """
23
- require 'example.rb'
23
+ require './example.rb'
24
24
 
25
25
  describe 4 do
26
26
  it "is 4" do
@@ -40,7 +40,7 @@ Feature: match unless raises
40
40
  Scenario: failing examples
41
41
  Given a file named "match_unless_raises_spec.rb" with:
42
42
  """
43
- require 'example.rb'
43
+ require './example.rb'
44
44
 
45
45
  describe 4 do
46
46
  it "is 4" do
@@ -17,7 +17,7 @@ Feature: match unless raises with an unexpected error
17
17
  Scenario: failing examples
18
18
  Given a file named "match_unless_raises_spec.rb" with:
19
19
  """
20
- require 'example.rb'
20
+ require './example.rb'
21
21
 
22
22
  describe 4 do
23
23
  it "is 4" do
@@ -36,4 +36,4 @@ Feature: match unless raises with an unexpected error
36
36
  When I run "spec match_unless_raises_spec.rb"
37
37
  Then the stdout should include "2 examples, 2 failures"
38
38
  Then the stdout should include "unexpected error"
39
-
39
+
@@ -1,10 +1,10 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "/../../lib")
1
+ $:.unshift File.expand_path("../../../lib", __FILE__)
2
2
 
3
3
  require 'spec/expectations'
4
4
  require 'forwardable'
5
5
  require 'tempfile'
6
- require 'spec/ruby_forker'
7
- require 'features/support/matchers/smart_match'
6
+ require './spec/ruby_forker'
7
+ require './features/support/matchers/smart_match'
8
8
  require 'spec/stubs/cucumber'
9
9
 
10
10
  class RspecWorld
@@ -239,7 +239,7 @@ module Spec
239
239
  @similar_messages ||= []
240
240
  end
241
241
 
242
- def advise(args, block)
242
+ def advise(*args)
243
243
  similar_messages << args
244
244
  end
245
245
 
@@ -40,16 +40,13 @@ module Spec
40
40
  def add_message_expectation(expected_from, sym, opts={}, &block)
41
41
  __add sym
42
42
  warn_if_nil_class sym
43
- @expectations << build_expectation(expected_from, sym, opts, &block)
44
- @expectations.last
45
- end
46
-
47
- def build_expectation(expected_from, sym, opts, &block)
48
- if stub = find_matching_method_stub(sym)
49
- stub.build_child(expected_from, block_given?? block : nil, 1, opts)
43
+ if existing_stub = @stubs.detect {|s| s.sym == sym }
44
+ expectation = existing_stub.build_child(expected_from, block_given?? block : nil, 1, opts)
50
45
  else
51
- MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
46
+ expectation = MessageExpectation.new(@error_generator, @expectation_ordering, expected_from, sym, block_given? ? block : nil, 1, opts)
52
47
  end
48
+ @expectations << expectation
49
+ @expectations.last
53
50
  end
54
51
 
55
52
  def add_negative_message_expectation(expected_from, sym, &block)
@@ -67,6 +64,7 @@ module Spec
67
64
 
68
65
  def remove_stub(message)
69
66
  message = message.to_sym
67
+
70
68
  if stub_to_remove = @stubs.detect { |s| s.matches_name?(message) }
71
69
  reset_proxied_method(message)
72
70
  @stubs.delete(stub_to_remove)
@@ -94,7 +92,7 @@ module Spec
94
92
  end
95
93
 
96
94
  def has_negative_expectation?(sym)
97
- @expectations.any? {|expectation| expectation.negative_expectation_for?(sym)}
95
+ @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
98
96
  end
99
97
 
100
98
  def record_message_received(sym, args, block)
@@ -105,41 +103,26 @@ module Spec
105
103
  expectation = find_matching_expectation(sym, *args)
106
104
  stub = find_matching_method_stub(sym, *args)
107
105
 
108
- if ok_to_invoke_stub?(stub, expectation)
109
- record_stub(stub, sym, args, &block)
106
+ if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
107
+ if expectation = find_almost_matching_expectation(sym, *args)
108
+ expectation.advise(*args) unless expectation.expected_messages_received?
109
+ end
110
+ stub.invoke(*args, &block)
110
111
  elsif expectation
111
- invoke_expectation(expectation, *args, &block)
112
+ expectation.invoke(*args, &block)
112
113
  elsif expectation = find_almost_matching_expectation(sym, *args)
113
- record_almost_matching_expectation(expectation, sym, *args, &block)
114
- elsif @target.is_a?(Class)
114
+ expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
115
+ raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(sym) or null_object?)
116
+ elsif stub = find_almost_matching_stub(sym, *args)
117
+ stub.advise(*args)
118
+ raise_unexpected_message_args_error(stub, *args)
119
+ elsif @target.is_a?(Class) && @target.superclass.respond_to?(sym, true)
115
120
  @target.superclass.send(sym, *args, &block)
116
121
  else
117
122
  @target.__send__ :method_missing, sym, *args, &block
118
123
  end
119
124
  end
120
125
 
121
- def record_stub(stub, sym, args, &block)
122
- almost_matching_expectation(sym, *args) do |e|
123
- e.advise(args, block)
124
- end
125
- stub.invoke(*args, &block)
126
- end
127
-
128
- def invoke_expectation(expectation, *args, &block)
129
- expectation.invoke(*args, &block)
130
- end
131
-
132
- def record_almost_matching_expectation(expectation, sym, *args, &block)
133
- expectation.advise(args, block)
134
- unless (null_object? or has_negative_expectation?(sym))
135
- raise_unexpected_message_args_error(expectation, *args)
136
- end
137
- end
138
-
139
- def ok_to_invoke_stub?(stub, expectation)
140
- stub && (!expectation || expectation.called_max_times?)
141
- end
142
-
143
126
  def raise_unexpected_message_args_error(expectation, *args)
144
127
  @error_generator.raise_unexpected_message_args_error expectation, *args
145
128
  end
@@ -151,7 +134,7 @@ module Spec
151
134
  def find_matching_method_stub(sym, *args)
152
135
  @stubs.find {|stub| stub.matches(sym, args)}
153
136
  end
154
-
137
+
155
138
  private
156
139
 
157
140
  def __add(sym)
@@ -223,11 +206,15 @@ module Spec
223
206
  end
224
207
 
225
208
  def verify_expectations
226
- @expectations.map {|e| e.verify_messages_received}
209
+ @expectations.each do |expectation|
210
+ expectation.verify_messages_received
211
+ end
227
212
  end
228
213
 
229
214
  def reset_proxied_methods
230
- @proxied_methods.map {|sym| reset_proxied_method(sym)}
215
+ @proxied_methods.each do |sym|
216
+ reset_proxied_method(sym)
217
+ end
231
218
  end
232
219
 
233
220
  def reset_proxied_method(sym)
@@ -254,15 +241,14 @@ module Spec
254
241
  @expectations.find {|expectation| expectation.matches(sym, args)}
255
242
  end
256
243
 
257
- def almost_matching_expectation(sym, *args, &block)
258
- if e = find_almost_matching_expectation(sym, *args)
259
- yield e
260
- end
261
- end
262
-
263
244
  def find_almost_matching_expectation(sym, *args)
264
245
  @expectations.find {|expectation| expectation.matches_name_but_not_args(sym, args)}
265
246
  end
247
+
248
+ def find_almost_matching_stub(sym, *args)
249
+ @stubs.find {|stub| stub.matches_name_but_not_args(sym, args)}
250
+ end
251
+
266
252
  end
267
253
  end
268
254
  end