rspec-expectations 2.0.0.beta.11 → 2.0.0.beta.12

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -23,10 +23,6 @@ begin
23
23
 
24
24
  Thank you for installing #{gem.summary}
25
25
 
26
- This is beta software. If you are looking
27
- for a supported production release, please
28
- "gem install rspec" (without --pre).
29
-
30
26
  #{"*"*50}
31
27
  EOM
32
28
  end
@@ -75,6 +71,7 @@ Rake::RDocTask.new do |rdoc|
75
71
  end
76
72
 
77
73
  task :clobber do
74
+ rm_rf 'doc'
78
75
  rm_rf 'pkg'
79
76
  rm_rf 'tmp'
80
77
  rm_rf 'coverage'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.11
1
+ 2.0.0.beta.12
@@ -1,7 +1,3 @@
1
- <%
2
- rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
- rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
- std_opts = "#{rerun_opts} --require features --format rerun --out rerun.txt --strict --tags ~@wip"
5
- %>
6
- default: <%= std_opts %>
1
+ default: --require features --tags ~@wip --format progress
7
2
  wip: --require features --tags @wip:3 --wip features
3
+
@@ -191,3 +191,32 @@ Feature: define matcher
191
191
  Then the exit status should be 0
192
192
  And the stdout should contain "1 example, 0 failures"
193
193
 
194
+ Scenario: scoped
195
+ Given a file named "scoped_matcher_spec.rb" with:
196
+ """
197
+ require 'rspec/expectations'
198
+
199
+ module MyHelpers
200
+ extend RSpec::Matchers::DSL
201
+
202
+ matcher :be_just_like do |expected|
203
+ match {|actual| actual == expected}
204
+ end
205
+ end
206
+
207
+ describe "group with MyHelpers" do
208
+ include MyHelpers
209
+ it "has access to the defined matcher" do
210
+ self.should respond_to(:be_just_like)
211
+ end
212
+ end
213
+
214
+ describe "group without MyHelpers" do
215
+ it "does not have access to the defined matcher" do
216
+ self.should_not respond_to(:be_just_like)
217
+ end
218
+ end
219
+ """
220
+
221
+ When I run "rspec ./scoped_matcher_spec.rb"
222
+ Then the stdout should contain "1 failure"
@@ -19,8 +19,9 @@ module RSpec
19
19
  file_length_difference = 0
20
20
  diffs.each do |piece|
21
21
  begin
22
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
23
- file_length_difference)
22
+ hunk = Diff::LCS::Hunk.new(
23
+ data_old, data_new, piece, context_lines, file_length_difference
24
+ )
24
25
  file_length_difference = hunk.file_length_difference
25
26
  next unless oldhunk
26
27
  # Hunks may overlap, which is why we need to be careful when our
@@ -44,7 +45,8 @@ module RSpec
44
45
  diff_as_string(PP.pp(target,""), PP.pp(expected,""))
45
46
  end
46
47
 
47
- protected
48
+ protected
49
+
48
50
  def format
49
51
  :unified
50
52
  end
@@ -8,21 +8,39 @@ module RSpec
8
8
  # raises a RSpec::Expectations::ExpectationNotMetError with message
9
9
  #
10
10
  # When a differ has been assigned and fail_with is passed
11
- # <code>expected</code> and <code>target</code>, passes them
11
+ # <code>expected</code> and <code>actual</code>, passes them
12
12
  # to the differ to append a diff message to the failure message.
13
- def fail_with(message, expected=nil, target=nil) # :nodoc:
14
- if message.nil?
13
+ def fail_with(message, expected=nil, actual=nil) # :nodoc:
14
+ if !message
15
15
  raise ArgumentError, "Failure message is nil. Does your matcher define the " +
16
16
  "appropriate failure_message_for_* method to return a string?"
17
17
  end
18
- unless (differ.nil? || expected.nil? || target.nil?)
19
- if expected.is_a?(String)
20
- message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
21
- elsif !target.is_a?(Proc)
22
- message << "\nDiff:" << self.differ.diff_as_object(target, expected)
18
+
19
+ if actual && expected
20
+ if all_strings?(actual, expected)
21
+ if any_multiline_strings?(actual, expected)
22
+ message << "\nDiff:" << self.differ.diff_as_string(actual, expected)
23
+ end
24
+ elsif no_procs?(actual, expected)
25
+ message << "\nDiff:" << self.differ.diff_as_object(actual, expected)
23
26
  end
24
27
  end
25
- Kernel::raise(RSpec::Expectations::ExpectationNotMetError.new(message))
28
+
29
+ raise(RSpec::Expectations::ExpectationNotMetError.new(message))
30
+ end
31
+
32
+ private
33
+
34
+ def no_procs?(*args)
35
+ args.none? {|a| Proc === a}
36
+ end
37
+
38
+ def all_strings?(*args)
39
+ args.all? {|a| String === a}
40
+ end
41
+
42
+ def any_multiline_strings?(*args)
43
+ all_strings?(*args) && args.any? {|a| a =~ /\n/}
26
44
  end
27
45
  end
28
46
  end
@@ -8,6 +8,8 @@ module RSpec
8
8
  RSpec::Matchers::Matcher.new name, *expected, &declarations
9
9
  end
10
10
  end
11
+
12
+ alias_method :matcher, :define
11
13
  end
12
14
  end
13
15
  end
@@ -5,13 +5,13 @@ module RSpec
5
5
  include RSpec::Matchers::Pretty
6
6
  include RSpec::Matchers
7
7
 
8
- attr_reader :expected, :actual
8
+ attr_reader :expected, :actual, :rescued_exception
9
9
  def initialize(name, *expected, &declarations)
10
10
  @name = name
11
11
  @expected = expected
12
12
  @actual = nil
13
13
  @diffable = false
14
- @expected_exception = nil
14
+ @expected_exception, @rescued_exception = nil
15
15
  @messages = {
16
16
  :description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
17
17
  :failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
@@ -29,7 +29,7 @@ module RSpec
29
29
  begin
30
30
  instance_exec(actual, &@match_block)
31
31
  true
32
- rescue @expected_exception
32
+ rescue @expected_exception => @rescued_exception
33
33
  false
34
34
  end
35
35
  else
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-expectations}
8
- s.version = "2.0.0.beta.11"
8
+ s.version = "2.0.0.beta.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-06-06}
12
+ s.date = %q{2010-06-14}
13
13
  s.description = %q{rspec expectations (should[_not] and matchers)}
14
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -110,19 +110,15 @@ Gem::Specification.new do |s|
110
110
  s.homepage = %q{http://github.com/rspec/expectations}
111
111
  s.post_install_message = %q{**************************************************
112
112
 
113
- Thank you for installing rspec-expectations-2.0.0.beta.11
113
+ Thank you for installing rspec-expectations-2.0.0.beta.12
114
114
 
115
- This is beta software. If you are looking
116
- for a supported production release, please
117
- "gem install rspec" (without --pre).
118
-
119
115
  **************************************************
120
116
  }
121
117
  s.rdoc_options = ["--charset=UTF-8"]
122
118
  s.require_paths = ["lib"]
123
119
  s.rubyforge_project = %q{rspec}
124
120
  s.rubygems_version = %q{1.3.6}
125
- s.summary = %q{rspec-expectations-2.0.0.beta.11}
121
+ s.summary = %q{rspec-expectations-2.0.0.beta.12}
126
122
  s.test_files = [
127
123
  "spec/rspec/expectations/differ_spec.rb",
128
124
  "spec/rspec/expectations/extensions/kernel_spec.rb",
@@ -165,21 +161,21 @@ Gem::Specification.new do |s|
165
161
  s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
166
162
  s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
167
163
  s.add_development_dependency(%q<aruba>, [">= 0.1.1"])
168
- s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.11"])
169
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.11"])
164
+ s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.12"])
165
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
170
166
  else
171
167
  s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
172
168
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
173
169
  s.add_dependency(%q<aruba>, [">= 0.1.1"])
174
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.11"])
175
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.11"])
170
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.12"])
171
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
176
172
  end
177
173
  else
178
174
  s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
179
175
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
180
176
  s.add_dependency(%q<aruba>, [">= 0.1.1"])
181
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.11"])
182
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.11"])
177
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.12"])
178
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.12"])
183
179
  end
184
180
  end
185
181
 
@@ -1,34 +1,40 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RSpec::Expectations, "#fail_with with diff" do
4
+ let(:differ) { double("differ") }
5
+
4
6
  before(:each) do
5
- @differ = mock("differ")
6
- RSpec::Expectations.stub(:differ) { @differ }
7
+ RSpec::Expectations.stub(:differ) { differ }
7
8
  end
8
9
 
9
- it "should not call differ if no expected/actual" do
10
+ it "does not call differ if no expected/actual" do
10
11
  lambda {
11
12
  RSpec::Expectations.fail_with "the message"
12
13
  }.should fail_with("the message")
13
14
  end
14
15
 
15
- it "should call differ if expected/actual are presented separately" do
16
- @differ.should_receive(:diff_as_string).and_return("diff")
16
+ it "calls differ if expected/actual are presented separately" do
17
+ differ.should_receive(:diff_as_string).and_return("diff")
17
18
  lambda {
18
- RSpec::Expectations.fail_with "the message", "expected", "actual"
19
+ RSpec::Expectations.fail_with "the message", "expected\nthis", "actual"
19
20
  }.should fail_with("the message\nDiff:diff")
20
21
  end
21
22
 
22
- it "should call differ if expected/actual are not strings" do
23
- @differ.should_receive(:diff_as_object).and_return("diff")
23
+ it "does not call differ if expected/actual are single line strings" do
24
+ differ.should_not_receive(:diff_as_string)
25
+ RSpec::Expectations.fail_with ("the message", "expected", "actual") rescue nil
26
+ end
27
+
28
+ it "calls differ if expected/actual are not strings" do
29
+ differ.should_receive(:diff_as_object).and_return("diff")
24
30
  lambda {
25
- RSpec::Expectations.fail_with "the message", :expected, :actual
31
+ RSpec::Expectations.fail_with "the message", Object.new, Object.new
26
32
  }.should fail_with("the message\nDiff:diff")
27
33
  end
28
34
 
29
- it "should not call differ if expected or actual are procs" do
30
- @differ.should_not_receive(:diff_as_string)
31
- @differ.should_not_receive(:diff_as_object)
35
+ it "does not call differ if expected or actual are procs" do
36
+ differ.should_not_receive(:diff_as_string)
37
+ differ.should_not_receive(:diff_as_object)
32
38
  lambda {
33
39
  RSpec::Expectations.fail_with "the message", lambda {}, lambda {}
34
40
  }.should fail_with("the message")
@@ -230,11 +230,11 @@ module RSpec
230
230
  end
231
231
 
232
232
  describe "#match_unless_raises" do
233
- context "with a passing assertion" do
233
+ context "with an assertion" do
234
234
  let(:mod) do
235
235
  Module.new do
236
236
  def assert_equal(a,b)
237
- a == b ? nil : (raise UnexpectedError.new("#{a} does not equal #{b}"))
237
+ a == b ? nil : (raise UnexpectedError.new("#{b} does not equal #{a}"))
238
238
  end
239
239
  end
240
240
  end
@@ -247,11 +247,23 @@ module RSpec
247
247
  end
248
248
  end
249
249
  end
250
- it "passes as you would expect" do
251
- matcher.matches?(4).should be_true
250
+
251
+ context "with passing assertion" do
252
+ it "passes" do
253
+ matcher.matches?(4).should be_true
254
+ end
252
255
  end
253
- it "fails as you would expect" do
254
- matcher.matches?(5).should be_false
256
+
257
+ context "with failing assertion" do
258
+ it "fails" do
259
+ matcher.matches?(5).should be_false
260
+ end
261
+
262
+ it "provides the raised exception" do
263
+ matcher.matches?(5)
264
+ matcher.rescued_exception.message.
265
+ should eq("5 does not equal 4")
266
+ end
255
267
  end
256
268
  end
257
269
 
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 11
11
- version: 2.0.0.beta.11
10
+ - 12
11
+ version: 2.0.0.beta.12
12
12
  platform: ruby
13
13
  authors:
14
14
  - David Chelimsky
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-06-06 00:00:00 -04:00
20
+ date: 2010-06-14 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -74,8 +74,8 @@ dependencies:
74
74
  - 0
75
75
  - 0
76
76
  - beta
77
- - 11
78
- version: 2.0.0.beta.11
77
+ - 12
78
+ version: 2.0.0.beta.12
79
79
  type: :development
80
80
  version_requirements: *id004
81
81
  - !ruby/object:Gem::Dependency
@@ -90,8 +90,8 @@ dependencies:
90
90
  - 0
91
91
  - 0
92
92
  - beta
93
- - 11
94
- version: 2.0.0.beta.11
93
+ - 12
94
+ version: 2.0.0.beta.12
95
95
  type: :development
96
96
  version_requirements: *id005
97
97
  description: rspec expectations (should[_not] and matchers)
@@ -200,12 +200,8 @@ licenses: []
200
200
  post_install_message: |
201
201
  **************************************************
202
202
 
203
- Thank you for installing rspec-expectations-2.0.0.beta.11
203
+ Thank you for installing rspec-expectations-2.0.0.beta.12
204
204
 
205
- This is beta software. If you are looking
206
- for a supported production release, please
207
- "gem install rspec" (without --pre).
208
-
209
205
  **************************************************
210
206
 
211
207
  rdoc_options:
@@ -234,7 +230,7 @@ rubyforge_project: rspec
234
230
  rubygems_version: 1.3.6
235
231
  signing_key:
236
232
  specification_version: 3
237
- summary: rspec-expectations-2.0.0.beta.11
233
+ summary: rspec-expectations-2.0.0.beta.12
238
234
  test_files:
239
235
  - spec/rspec/expectations/differ_spec.rb
240
236
  - spec/rspec/expectations/extensions/kernel_spec.rb