rspec-expectations 2.0.0.beta.3 → 2.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.beta.3
1
+ 2.0.0.beta.4
@@ -4,4 +4,4 @@ rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format
4
4
  std_opts = "#{rerun_opts} --require features --format rerun --out rerun.txt --strict --tags ~@wip"
5
5
  %>
6
6
  default: <%= std_opts %>
7
- wip: --tags @wip:3 --wip features
7
+ wip: --require features --tags @wip:3 --wip features
@@ -0,0 +1,48 @@
1
+ @wip
2
+ Feature: access running example
3
+
4
+ Scenario: matcher defined via DSL
5
+ Given a file named "example_spec.rb" with:
6
+ """
7
+ Rspec::Matchers.define :bar do
8
+ match do |_|
9
+ running_example.foo == "foo"
10
+ end
11
+ end
12
+
13
+ describe "something" do
14
+ def foo
15
+ "foo"
16
+ end
17
+
18
+ it "does something" do
19
+ "foo".should bar
20
+ end
21
+ end
22
+ """
23
+ When I run "rspec example_spec.rb"
24
+ Then I should see "1 example, 0 failures"
25
+
26
+ Scenario: matcher defined via #new
27
+ Given a file named "example_spec.rb" with:
28
+ """
29
+ describe "something" do
30
+ def bar
31
+ Rspec::Matchers::Matcher.new :bar do
32
+ match do |_|
33
+ running_example.foo == "foo"
34
+ end
35
+ end
36
+ end
37
+
38
+ def foo
39
+ "foo"
40
+ end
41
+
42
+ it "does something" do
43
+ "foo".should bar
44
+ end
45
+ end
46
+ """
47
+ When I run "rspec example_spec.rb"
48
+ Then I should see "1 example, 0 failures"
@@ -1,12 +1,7 @@
1
1
  begin
2
2
  require 'diff/lcs'
3
3
  rescue LoadError
4
- begin
5
- require 'rubygems' unless ENV['NO_RUBYGEMS']
6
- require 'diff/lcs'
7
- rescue LoadError
8
- raise "You must gem install diff-lcs to use diffing"
9
- end
4
+ raise "You must gem install diff-lcs to use diffing"
10
5
  end
11
6
 
12
7
  require 'diff/lcs/hunk'
@@ -15,14 +15,14 @@ module Rspec
15
15
  orig_critical, Thread.critical = Thread.critical, true
16
16
  n = 0
17
17
  n += 1 while respond_to?(method_name="__instance_exec#{n}")
18
- singleton_class.module_eval{ define_method(:__instance_exec, &block) }
18
+ singleton_class.module_eval{ define_method(method_name, &block) }
19
19
  ensure
20
20
  Thread.critical = orig_critical
21
21
  end
22
22
  begin
23
- return send(:__instance_exec, *args)
23
+ return send(method_name, *args)
24
24
  ensure
25
- singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
25
+ singleton_class.module_eval{ remove_method(method_name) } rescue nil
26
26
  end
27
27
  end
28
28
  end
@@ -6,7 +6,6 @@ module Rspec
6
6
  include Rspec::Matchers
7
7
 
8
8
  attr_reader :expected, :actual
9
-
10
9
  def initialize(name, *expected, &declarations)
11
10
  @name = name
12
11
  @expected = expected
@@ -22,7 +21,12 @@ module Rspec
22
21
  instance_exec(*@expected, &declarations)
23
22
  end
24
23
  end
25
-
24
+
25
+ def instance_exec(*args, &block)
26
+ self.running_example ||= eval("running_example", block.binding) rescue nil
27
+ super(*args, &block)
28
+ end
29
+
26
30
  #Used internally by objects returns by +should+ and +should_not+.
27
31
  def matches?(actual)
28
32
  @actual = actual
@@ -87,9 +91,12 @@ module Rspec
87
91
  end
88
92
  end
89
93
  end
90
-
94
+
95
+ protected
96
+ attr_accessor :running_example
97
+
91
98
  private
92
-
99
+
93
100
  def making_declared_methods_public # :nodoc:
94
101
  # Our home-grown instance_exec in ruby 1.8.6 results in any methods
95
102
  # declared in the block eval'd by instance_exec in the block to which we
@@ -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.3"
8
+ s.version = "2.0.0.beta.4"
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-03-08}
12
+ s.date = %q{2010-03-15}
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 = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "cucumber.yml",
27
27
  "features/expectations/customized_message.feature",
28
28
  "features/expectations/implicit_docstrings.feature",
29
+ "features/matchers/access_running_example.feature",
29
30
  "features/matchers/define_diffable_matcher.feature",
30
31
  "features/matchers/define_matcher.feature",
31
32
  "features/matchers/define_matcher_outside_rspec.feature",
@@ -102,12 +103,13 @@ Gem::Specification.new do |s|
102
103
  "spec/rspec/matchers/throw_symbol_spec.rb",
103
104
  "spec/spec_helper.rb",
104
105
  "spec/suite.rb",
105
- "spec/support/classes.rb"
106
+ "spec/support/classes.rb",
107
+ "specs.watchr"
106
108
  ]
107
109
  s.homepage = %q{http://github.com/rspec/expectations}
108
110
  s.post_install_message = %q{**************************************************
109
111
 
110
- Thank you for installing rspec-expectations-2.0.0.beta.3
112
+ Thank you for installing rspec-expectations-2.0.0.beta.4
111
113
 
112
114
  This is beta software. If you are looking
113
115
  for a supported production release, please
@@ -119,7 +121,7 @@ Gem::Specification.new do |s|
119
121
  s.require_paths = ["lib"]
120
122
  s.rubyforge_project = %q{rspec}
121
123
  s.rubygems_version = %q{1.3.6}
122
- s.summary = %q{rspec-expectations-2.0.0.beta.3}
124
+ s.summary = %q{rspec-expectations-2.0.0.beta.4}
123
125
  s.test_files = [
124
126
  "spec/rspec/expectations/differs/default_spec.rb",
125
127
  "spec/rspec/expectations/extensions/kernel_spec.rb",
@@ -161,19 +163,19 @@ Gem::Specification.new do |s|
161
163
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
162
164
  s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
163
165
  s.add_development_dependency(%q<aruba>, [">= 0.1.1"])
164
- s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.3"])
165
- s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.3"])
166
+ s.add_development_dependency(%q<rspec-core>, [">= 2.0.0.beta.4"])
167
+ s.add_development_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.4"])
166
168
  else
167
169
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
168
170
  s.add_dependency(%q<aruba>, [">= 0.1.1"])
169
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.3"])
170
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.3"])
171
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.4"])
172
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.4"])
171
173
  end
172
174
  else
173
175
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
174
176
  s.add_dependency(%q<aruba>, [">= 0.1.1"])
175
- s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.3"])
176
- s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.3"])
177
+ s.add_dependency(%q<rspec-core>, [">= 2.0.0.beta.4"])
178
+ s.add_dependency(%q<rspec-mocks>, [">= 2.0.0.beta.4"])
177
179
  end
178
180
  end
179
181
 
@@ -15,8 +15,8 @@ module Rspec
15
15
  obj = Object.new
16
16
  obj.extend mod
17
17
 
18
- Rspec::Matchers::Matcher.should_receive(:new).with(:foo, 3)
19
-
18
+ Rspec::Matchers::Matcher.should_receive(:new).with(:foo, 3) { stub('matcher').as_null_object }
19
+
20
20
  obj.foo(3)
21
21
  end
22
22
  end
@@ -284,6 +284,39 @@ module Rspec
284
284
  matcher.expecting('value').matches?('value').should be_true
285
285
  matcher.expecting('value').matches?('other value').should be_false
286
286
  end
287
+
288
+ context "defined using the dsl" do
289
+ it "can access the running_example" do
290
+ Rspec::Matchers.define(:__access_running_example) do
291
+ match do |actual|
292
+ actual == running_example
293
+ end
294
+ end
295
+ running_example.should __access_running_example
296
+ end
297
+ end
298
+
299
+ context "defined using #new" do
300
+ it "can access the running_example" do
301
+ @matcher = Rspec::Matchers::Matcher.new(:something) {}
302
+ @matcher.send(:running_example).should eq(running_example)
303
+ end
304
+ end
305
+
306
+ context "wrapped in a method" do
307
+
308
+ def access_running_example
309
+ Matcher.new(:access_running_example) do
310
+ match do |actual|
311
+ actual == running_example
312
+ end
313
+ end
314
+ end
315
+
316
+ it "can access the running_example" do
317
+ running_example.should access_running_example
318
+ end
319
+ end
287
320
  end
288
321
  end
289
322
  end
@@ -0,0 +1,57 @@
1
+ # Run me with:
2
+ #
3
+ # $ watchr specs.watchr
4
+
5
+ # --------------------------------------------------
6
+ # Convenience Methods
7
+ # --------------------------------------------------
8
+ def all_test_files
9
+ Dir['spec/**/*_spec.rb']
10
+ end
11
+
12
+ def run_test_matching(thing_to_match)
13
+ matches = all_test_files.grep(/#{thing_to_match}/i)
14
+ if matches.empty?
15
+ puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
16
+ else
17
+ run matches.join(' ')
18
+ end
19
+ end
20
+
21
+ def run(files_to_run)
22
+ puts("Running: #{files_to_run}")
23
+ system("clear;rspec -cfs #{files_to_run}")
24
+ no_int_for_you
25
+ end
26
+
27
+ def run_all_tests
28
+ run(all_test_files.join(' '))
29
+ end
30
+
31
+ # --------------------------------------------------
32
+ # Watchr Rules
33
+ # --------------------------------------------------
34
+ watch('^spec/(.*)_spec\.rb' ) { |m| run_test_matching(m[1]) }
35
+ watch('^lib/(.*)\.rb' ) { |m| run_test_matching(m[1]) }
36
+ watch('^spec/spec_helper\.rb') { run_all_tests }
37
+ # --------------------------------------------------
38
+ # Signal Handling
39
+ # --------------------------------------------------
40
+
41
+ def no_int_for_you
42
+ @sent_an_int = nil
43
+ end
44
+
45
+ Signal.trap 'INT' do
46
+ if @sent_an_int then
47
+ puts " A second INT? Ok, I get the message. Shutting down now."
48
+ exit
49
+ else
50
+ puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
51
+ @sent_an_int = true
52
+ Kernel.sleep 1.5
53
+ run_all_tests
54
+ end
55
+ end
56
+
57
+ # vim:ft=ruby
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 3
11
- version: 2.0.0.beta.3
10
+ - 4
11
+ version: 2.0.0.beta.4
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-03-08 00:00:00 -06:00
20
+ date: 2010-03-15 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -60,8 +60,8 @@ dependencies:
60
60
  - 0
61
61
  - 0
62
62
  - beta
63
- - 3
64
- version: 2.0.0.beta.3
63
+ - 4
64
+ version: 2.0.0.beta.4
65
65
  type: :development
66
66
  version_requirements: *id003
67
67
  - !ruby/object:Gem::Dependency
@@ -76,8 +76,8 @@ dependencies:
76
76
  - 0
77
77
  - 0
78
78
  - beta
79
- - 3
80
- version: 2.0.0.beta.3
79
+ - 4
80
+ version: 2.0.0.beta.4
81
81
  type: :development
82
82
  version_requirements: *id004
83
83
  description: rspec expectations (should[_not] and matchers)
@@ -99,6 +99,7 @@ files:
99
99
  - cucumber.yml
100
100
  - features/expectations/customized_message.feature
101
101
  - features/expectations/implicit_docstrings.feature
102
+ - features/matchers/access_running_example.feature
102
103
  - features/matchers/define_diffable_matcher.feature
103
104
  - features/matchers/define_matcher.feature
104
105
  - features/matchers/define_matcher_outside_rspec.feature
@@ -176,6 +177,7 @@ files:
176
177
  - spec/spec_helper.rb
177
178
  - spec/suite.rb
178
179
  - spec/support/classes.rb
180
+ - specs.watchr
179
181
  has_rdoc: true
180
182
  homepage: http://github.com/rspec/expectations
181
183
  licenses: []
@@ -183,7 +185,7 @@ licenses: []
183
185
  post_install_message: |
184
186
  **************************************************
185
187
 
186
- Thank you for installing rspec-expectations-2.0.0.beta.3
188
+ Thank you for installing rspec-expectations-2.0.0.beta.4
187
189
 
188
190
  This is beta software. If you are looking
189
191
  for a supported production release, please
@@ -217,7 +219,7 @@ rubyforge_project: rspec
217
219
  rubygems_version: 1.3.6
218
220
  signing_key:
219
221
  specification_version: 3
220
- summary: rspec-expectations-2.0.0.beta.3
222
+ summary: rspec-expectations-2.0.0.beta.4
221
223
  test_files:
222
224
  - spec/rspec/expectations/differs/default_spec.rb
223
225
  - spec/rspec/expectations/extensions/kernel_spec.rb