rspec-power_assert 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee25dc13d41d0ae9cbdb0a957216505df476a2dd
4
- data.tar.gz: 167b50a4d9b7ee238b2d6c9df0f119f84c9659db
3
+ metadata.gz: 0fb00b915c73e7026a8842c179fab476f44aeb64
4
+ data.tar.gz: 6dc75022730b389924604985e5c64b788e8127eb
5
5
  SHA512:
6
- metadata.gz: c899e6100bae4a8ca8cf855038e0571f01ab238ad0b811d7af8309cfcac5052fb6d4e6a1b07181bac211d1b0687ff27e5542d27649084f399f8e182504b18e28
7
- data.tar.gz: c995dde200ede1ab571ca274ec1578e054c129375820af7892eed358021183f1f66646af6a3bb1f62e7308eca5fcbf11a72ebe6539c64d334bd09de1dcb5a617
6
+ metadata.gz: 09fe61c3d55ea9c7cb3d3514e63dc292e6386506246b069feb1b8651aaf14122f6eaaafeda8847ebcc1df3a2177c18703f7112e83b9e7f8f2e34b3e3173bbaf2
7
+ data.tar.gz: 32e80591b88a0aa9fe3c403d76f0ac9c14273f95ded1150f198b7cf8df4425ace4d3706911db950991867c5a9657da3d4c4ea7246cfe58241fa34783cc4ab7cc
data/README.md CHANGED
@@ -252,6 +252,38 @@ rspec ./spec/rspec/power_assert_spec.rb:50 # Rspec::PowerAssert Array#map
252
252
  rspec ./spec/rspec/power_assert_spec.rb:56 # Rspec::PowerAssert Array#map succ each element
253
253
  ```
254
254
 
255
+ On RSpec-3.3 or later, support `aggregate_failures`
256
+ (Thanks sue445)
257
+
258
+ ```
259
+ 2) Rspec::PowerAssert Array#map When use aggregate_failures should be called be is_asserted_by with 3 times
260
+ Got 2 failures from failure aggregation block.
261
+ # ./spec/rspec/power_assert_spec.rb:81:in `block (5 levels) in <top (required)>'
262
+
263
+ 2.1) Failure/Error: is_asserted_by { subject.map(&:upcase) == %w(a b c) }
264
+ is_asserted_by { subject.map(&:upcase) == %w(a b c) }
265
+ | | |
266
+ | | false
267
+ | ["A", "B", "C"]
268
+ ["a", "b", "c"]
269
+ # ./lib/rspec/power_assert.rb:81:in `handle_result_and_message'
270
+ # ./lib/rspec/power_assert.rb:50:in `is_asserted_by'
271
+ # ./spec/rspec/power_assert_spec.rb:82:in `block (6 levels) in <top (required)>'
272
+
273
+ 2.2) Failure/Error: is_asserted_by { subject.map(&:upcase) == %w(A B C D) }
274
+ is_asserted_by { subject.map(&:upcase) == %w(A B C D) }
275
+ | | |
276
+ | | false
277
+ | ["A", "B", "C"]
278
+ ["a", "b", "c"]
279
+ # ./lib/rspec/power_assert.rb:81:in `handle_result_and_message'
280
+ # ./lib/rspec/power_assert.rb:50:in `is_asserted_by'
281
+ # ./spec/rspec/power_assert_spec.rb:84:in `block (6 levels) in <top (required)>'
282
+
283
+ Finished in 0.02937 seconds (files took 0.19416 seconds to load)
284
+ 2 examples, 2 failures
285
+ ```
286
+
255
287
  ## Contributing
256
288
 
257
289
  1. Fork it ( https://github.com/joker1007/rspec-power_assert/fork )
@@ -46,7 +46,8 @@ module RSpec
46
46
  [tp.yield, tp.message_proc.call]
47
47
  end
48
48
 
49
- handle_result_and_message(result, msg, __callee__)
49
+ location = blk.source_location.join(":")
50
+ handle_result_and_message(result, msg, __callee__, location)
50
51
  end
51
52
 
52
53
  private
@@ -59,10 +60,11 @@ module RSpec
59
60
  [tp.yield, tp.message_proc.call]
60
61
  end
61
62
 
62
- handle_result_and_message(result, msg, method_name)
63
+ location = blk.source_location.join(":")
64
+ handle_result_and_message(result, msg, method_name, location)
63
65
  end
64
66
 
65
- def handle_result_and_message(result, msg, method_name)
67
+ def handle_result_and_message(result, msg, method_name, location)
66
68
  if result
67
69
  RSpec::Matchers.last_matcher = DummyAssertionMatcher.new(msg, method_name.to_s)
68
70
 
@@ -72,7 +74,16 @@ module RSpec
72
74
  RSpec::Matchers.last_expectation_handler = DummyExpectationHandler # for RSpec 3
73
75
  end
74
76
  else
75
- raise RSpec::Expectations::ExpectationNotMetError, msg
77
+ ex = RSpec::Expectations::ExpectationNotMetError.new(msg)
78
+
79
+ if defined?(RSpec::Support) && RSpec::Support.respond_to?(:notify_failure)
80
+ # for RSpec 3.3+
81
+ RSpec::Support.notify_failure(ex)
82
+ else
83
+ # for RSpec 2, 3.0, 3.1, 3.2
84
+ ex.set_backtrace(location)
85
+ raise ex
86
+ end
76
87
  end
77
88
  end
78
89
 
@@ -135,9 +146,11 @@ module RSpec
135
146
  end
136
147
 
137
148
  def it_is_asserted_by(description = nil, &blk)
138
- file, lineno = blk.source_location
139
- cmd = description ? "it(description)" : "specify"
140
- eval %{#{cmd} do evaluate_example("#{__callee__}", &blk) end}, binding, file, lineno
149
+ file, _lineno = blk.source_location
150
+ backtrace = caller.drop_while {|l| l !~ /#{Regexp.escape(file)}/}
151
+ it description, caller: backtrace do
152
+ evaluate_example(__callee__, &blk)
153
+ end
141
154
  end
142
155
  end
143
156
  end
@@ -1,5 +1,5 @@
1
1
  module Rspec
2
2
  module PowerAssert
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -67,6 +67,38 @@ describe Rspec::PowerAssert do
67
67
  it_is_asserted_by "succ each element" do
68
68
  subject.map(&:succ) == ["b", "c", "e"] + @array
69
69
  end
70
+
71
+ context "When use aggregate_failures" do
72
+ before do
73
+ unless respond_to?(:aggregate_failures)
74
+ pending_message = "This test can run only on RSpec 3.3+"
75
+
76
+ if respond_to?(:skip)
77
+ # for RSpec 3
78
+ skip pending_message
79
+ else
80
+ # for RSpec 2
81
+ pending pending_message
82
+ end
83
+ end
84
+ end
85
+
86
+ it "should be called expect with 3 times" do
87
+ aggregate_failures do
88
+ expect(subject.map(&:upcase)).to eq %w(a b c)
89
+ expect(subject.map(&:upcase)).to eq %w(A B C)
90
+ expect(subject.map(&:upcase)).to eq %w(A B C D)
91
+ end
92
+ end
93
+
94
+ it "should be called is_asserted_by with 3 times" do
95
+ aggregate_failures do
96
+ is_asserted_by { subject.map(&:upcase) == %w(a b c) }
97
+ is_asserted_by { subject.map(&:upcase) == %w(A B C) }
98
+ is_asserted_by { subject.map(&:upcase) == %w(A B C D) }
99
+ end
100
+ end
101
+ end
70
102
  end
71
103
  end
72
104
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-power_assert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-11 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: power_assert
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  requirements: []
108
108
  rubyforge_project:
109
- rubygems_version: 2.4.2
109
+ rubygems_version: 2.4.6
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Power Assert for RSpec.