rspec-core 2.2.1 → 2.3.0

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/.rspec ADDED
File without changes
data/Gemfile CHANGED
@@ -1,5 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ ### rspec libs
3
4
  %w[rspec-core rspec-expectations rspec-mocks].each do |lib|
4
5
  library_path = File.expand_path("../../#{lib}", __FILE__)
5
6
  if File.exist?(library_path)
@@ -9,28 +10,38 @@ source "http://rubygems.org"
9
10
  end
10
11
  end
11
12
 
12
- gem "rake"
13
+ ### dev dependencies
14
+ gem "rake", "0.8.7"
13
15
  gem "cucumber", "0.9.4"
14
16
  gem "aruba", "0.2.2"
15
- gem "autotest"
16
- gem "rcov"
17
- gem "mocha"
18
- gem "rr"
19
- gem "flexmock"
20
- gem "nokogiri"
21
- gem "syntax"
22
- gem "relish", "~> 0.0.3"
23
- gem "guard-rspec"
24
- gem "growl"
17
+ gem "rcov", "0.9.9"
18
+ gem "relish", "0.2.0"
19
+ gem "guard-rspec", "0.1.9"
20
+ gem "growl", "1.0.3"
21
+ gem "ZenTest", "~> 4.4.2"
22
+ gem "nokogiri", "1.4.4"
23
+
24
+ if RUBY_PLATFORM =~ /darwin/
25
+ gem "autotest-fsevent", "~> 0.2.4"
26
+ gem "autotest-growl", "~> 0.2.9"
27
+ end
25
28
 
26
29
  gem "ruby-debug", :platforms => :ruby_18
27
- gem "ruby-debug19", :platforms => :ruby_19
30
+ gem "ruby-debug19", "~> 0.11.6", :platforms => :ruby_19
28
31
 
29
32
  platforms :ruby_18, :ruby_19 do
30
- gem "rb-fsevent"
31
- gem "ruby-prof"
33
+ gem "rb-fsevent", "~> 0.3.9"
34
+ gem "ruby-prof", "~> 0.9.2"
32
35
  end
33
36
 
34
37
  platforms :jruby do
35
38
  gem "jruby-openssl"
36
39
  end
40
+
41
+ ### rspec-core only
42
+ gem "mocha", "~> 0.9.10"
43
+ gem "rr", "~> 1.0.2"
44
+ gem "flexmock", "~> 0.8.11"
45
+
46
+ ### optional runtime deps
47
+ gem "syntax", "1.0.0"
@@ -1,8 +1,26 @@
1
1
  ## rspec-core release history (incomplete)
2
2
 
3
- ### 2.2.1 / in development
3
+ ### 2.3.0 / 2010-12-12
4
4
 
5
- [full changelog](http://github.com/rspec/rspec-core/compare/v2.2.0...master)
5
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.2.1...v2.3.0)
6
+
7
+ * Enhancements
8
+ * tell autotest to use "rspec2" if it sees a .rspec file in the project's
9
+ root directory
10
+ * replaces the need for ./autotest/discover.rb, which will not work with
11
+ all versions of ZenTest and/or autotest
12
+ * config.expect_with
13
+ * :rspec # => rspec/expectations
14
+ * :stdlib # => test/unit/assertions
15
+ * :rspec, :stdlib # => both
16
+
17
+ * Bug fixes
18
+ * fix dev Gemfile to work on non-mac-os machines (Lake Denman)
19
+ * ensure explicit subject is only eval'd once (Laszlo Bacsi)
20
+
21
+ ### 2.2.1 / 2010-11-28
22
+
23
+ [full changelog](http://github.com/rspec/rspec-core/compare/v2.2.0...v2.2.1)
6
24
 
7
25
  * Bug fixes
8
26
  * alias_method instead of override Kernel#method_missing (John Wilger)
data/README.md CHANGED
@@ -4,10 +4,10 @@ Behaviour Driven Development for Ruby
4
4
 
5
5
  ## Documentation
6
6
 
7
- The [Cucumber features](http://relishapp.com/rspec/rspec-core/v/2-1) are the
7
+ The [Cucumber features](http://relishapp.com/rspec/rspec-core) are the
8
8
  most comprehensive and up-to-date docs for end-users.
9
9
 
10
- The [RDoc](http://rubydoc.info/gems/rspec-core/2.1/frames) provides
10
+ The [RDoc](http://rubydoc.info/gems/rspec-core/2.3.0/frames) provides
11
11
  additional information for contributors and/or extenders.
12
12
 
13
13
  All of the documentation is open source and a work in progress. If you find it
@@ -1,3 +1,26 @@
1
+ # rspec-core-2.3
2
+
3
+ ## autotest integration
4
+
5
+ Add a .rspec file to the project's root directory to tell RSpec to tell
6
+ Autotest to use RSpec's specialized Autotest class.
7
+
8
+ NOTE that rspec-core-2.0, 2.1, and 2.2 required an autotest/discover.rb file in
9
+ the project's root directory. This worked with some, but not all versions of
10
+ autotest and/or the autotest command that ships with ZenTest. This new approach
11
+ will work regardless of which version of autotest/ZenTest you are using.
12
+
13
+ ## config.expect_with
14
+
15
+ Use this to configure RSpec to use rspec/expectations (default),
16
+ test/unit/assertions, or both:
17
+
18
+ RSpec.configure do |config|
19
+ config.expect_with :rspec # => rspec/expectations
20
+ config.expect_with :stdlib # => test/unit/assertions
21
+ config.expect_with :rspec, :stdlib # => both
22
+ end
23
+
1
24
  # rspec-core-2.2
2
25
 
3
26
  ## FASTER!
@@ -8,6 +8,34 @@ rspec-core provides the structure for RSpec code examples:
8
8
  end
9
9
  end
10
10
 
11
+ ### Autotest integration
12
+
13
+ RSpec ships with a specialized subclass of Autotest. You can pass the --style
14
+ option to the autotest command to tell Autotest to load this subclass:
15
+
16
+ $ autotest --style rspec2
17
+
18
+ Alternatively, you can configure your project such that this happens
19
+ automatically, in which case you can just type:
20
+
21
+ $ autotest
22
+
23
+ Here's how:
24
+
25
+ #### rspec-2.3 and up
26
+
27
+ Add a .rspec file to the project's root directory if it's not already there.
28
+ You can use this to configure RSpec options, but you don't have to. As long as
29
+ RSpec sees this file, it will tell Autotest to use the "rspec2" style.
30
+
31
+ #### rspec-2.2 and down
32
+
33
+ Add an autotest directory to the project root, and add a file named discover.rb to
34
+ that directory with the following:
35
+
36
+ # in ./autotest/discover.rb
37
+ Autotest.add_discovery {"rspec2"}
38
+
11
39
  ## Issues
12
40
 
13
41
  The documentation for rspec-core is a work in progress. We'll be adding
@@ -1,18 +1,23 @@
1
1
  Feature: basic structure
2
2
 
3
- RSpec provides a DSL for creating executable examples of how code is expected
4
- to behave, organized in groups. It uses the words "describe" and "it" so we can
3
+ RSpec is a DSL for creating executable examples of how code is expected to
4
+ behave, organized in groups. It uses the words "describe" and "it" so we can
5
5
  express concepts like a conversation:
6
6
 
7
7
  "Describe an account when it is first opened."
8
8
  "It has a balance of zero."
9
9
 
10
- Use the describe() method to declare an example group. This defines a
11
- subclass of RSpec's ExampleGroup class. Within a group, you can declare
12
- nested groups using the describe() or context() methods.
10
+ The describe() method creates a subclass of RSpec::Core::ExampleGroup. The
11
+ block passed to describe() is evaluated in the context of that class, so any
12
+ class methods of ExampleGroup are at your disposal within that block.
13
13
 
14
- Use the it() method to declare an example. This, effectively, defines a
15
- method that is run in an instance of the group in which it is declared.
14
+ Within a group, you can declare nested groups using the describe() or
15
+ context() methods. A nested group is actually a subclass of the outer group,
16
+ so it has access to same methods as the outer group, as well as any class
17
+ methods defined in the outer group.
18
+
19
+ The it() method accepts a block, which is later executed in the context of
20
+ an instance of the group in which it is declared.
16
21
 
17
22
  Scenario: one group, one example
18
23
  Given a file named "sample_spec.rb" with:
@@ -0,0 +1,63 @@
1
+ Feature: configure expectation framework
2
+
3
+ By default, RSpec is configured to include rspec-expectations for expressing
4
+ desired outcomes. You can also configure RSpec to use:
5
+
6
+ rspec/expectations (explicitly)
7
+ test/unit/assertions
8
+ rspec/expecations _and_ test/unit assertions
9
+
10
+ Scenario: configure rspec-expectations (explicitly)
11
+ Given a file named "example_spec.rb" with:
12
+ """
13
+ RSpec.configure do |config|
14
+ config.expect_with :rspec
15
+ end
16
+
17
+ describe 5 do
18
+ it "is greater than 4" do
19
+ 5.should be > 4
20
+ end
21
+ end
22
+ """
23
+ When I run "rspec example_spec.rb"
24
+ Then the output should contain "1 example, 0 failures"
25
+ And the exit status should be 0
26
+
27
+ Scenario: configure test/unit assertions
28
+ Given a file named "example_spec.rb" with:
29
+ """
30
+ RSpec.configure do |config|
31
+ config.expect_with :stdlib
32
+ end
33
+
34
+ describe 5 do
35
+ it "is greater than 4" do
36
+ assert 5 > 4, "expected 5 to be greater than 4"
37
+ end
38
+ end
39
+ """
40
+ When I run "rspec example_spec.rb"
41
+ Then the output should contain "1 example, 0 failures"
42
+ And the exit status should be 0
43
+
44
+ Scenario: configure rspec/expecations AND test/unit assertions
45
+ Given a file named "example_spec.rb" with:
46
+ """
47
+ RSpec.configure do |config|
48
+ config.expect_with :rspec, :stdlib
49
+ end
50
+
51
+ describe 5 do
52
+ it "is greater than 4" do
53
+ assert 5 > 4, "expected 5 to be greater than 4"
54
+ end
55
+
56
+ it "is less than 4" do
57
+ 5.should be < 6
58
+ end
59
+ end
60
+ """
61
+ When I run "rspec example_spec.rb"
62
+ Then the output should contain "2 examples, 0 failures"
63
+ And the exit status should be 0
@@ -236,36 +236,36 @@ Feature: around hooks
236
236
 
237
237
  Scenario: multiple around hooks in the same scope
238
238
  Given a file named "example_spec.rb" with:
239
- """
240
- describe "if there are multiple around hooks in the same scope" do
241
- around(:each) do |example|
242
- puts "first around hook before"
243
- example.run
244
- puts "first around hook after"
245
- end
239
+ """
240
+ describe "if there are multiple around hooks in the same scope" do
241
+ around(:each) do |example|
242
+ puts "first around hook before"
243
+ example.run
244
+ puts "first around hook after"
245
+ end
246
246
 
247
- around(:each) do |example|
248
- puts "second around hook before"
249
- example.run
250
- puts "second around hook after"
251
- end
247
+ around(:each) do |example|
248
+ puts "second around hook before"
249
+ example.run
250
+ puts "second around hook after"
251
+ end
252
252
 
253
- it "they should all be run" do
254
- puts "in the example"
255
- 1.should == 1
253
+ it "they should all be run" do
254
+ puts "in the example"
255
+ 1.should == 1
256
+ end
256
257
  end
257
- end
258
- """
258
+ """
259
259
  When I run "rspec example_spec.rb"
260
260
  Then the output should contain "1 example, 0 failure"
261
261
  And the output should contain:
262
- """
263
- first around hook before
264
- second around hook before
265
- in the example
266
- second around hook after
267
- first around hook after
268
- """
262
+ """
263
+ first around hook before
264
+ second around hook before
265
+ in the example
266
+ second around hook after
267
+ first around hook after
268
+ """
269
269
 
270
270
  Scenario: around hooks in multiple scopes
271
271
  Given a file named "example_spec.rb" with:
@@ -8,7 +8,7 @@ Feature: described class
8
8
  """
9
9
  describe Fixnum do
10
10
  it "is available as described_class" do
11
- described_class.should == Fixnum
11
+ described_class.should eq(Fixnum)
12
12
  end
13
13
  end
14
14
  """
@@ -0,0 +1,106 @@
1
+ Feature: mock with an alternative framework
2
+
3
+ In addition to rspec, mocha, flexmock, and RR, you can choose an alternate
4
+ framework as the mocking framework. You (or the framework authors) just needs
5
+ to provide an adapter that hooks RSpec's events into those of the framework.
6
+
7
+ A mock framework adapter must expose three methods:
8
+
9
+ * setup_mocks_for_rspec
10
+ * called before each example is run
11
+ * verify_mocks_for_rspec
12
+ * called after each example is run
13
+ * this is where message expectation failures should result in an error with
14
+ the appropriate failure message
15
+ * teardown_mocks_for_rspec
16
+ * called after verify_mocks_for_rspec
17
+ * use this to clean up resources, restore objects to earlier state, etc
18
+ * guaranteed to run even if there are failures
19
+
20
+ Scenario: Mock with alternate framework
21
+ Given a file named "expector.rb" with:
22
+ """
23
+ class Expector
24
+ class << self
25
+ def expectors
26
+ @expectors ||= []
27
+ end
28
+
29
+ def clear_expectors
30
+ expectors.clear
31
+ end
32
+
33
+ def verify_expectors
34
+ expectors.each {|d| d.verify}
35
+ end
36
+ end
37
+
38
+ def initialize
39
+ self.class.expectors << self
40
+ end
41
+
42
+ def expectations
43
+ @expectations ||= []
44
+ end
45
+
46
+ def expect(message)
47
+ expectations << message.to_s
48
+ end
49
+
50
+ def verify
51
+ unless expectations.empty?
52
+ raise expectations.map {|e|
53
+ "expected #{e}, but it was never received"
54
+ }.join("\n")
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def method_missing(name, *args, &block)
61
+ expectations.delete(name.to_s)
62
+ end
63
+
64
+ public
65
+
66
+ module RSpecAdapter
67
+ def setup_mocks_for_rspec
68
+ # no setup necessary
69
+ end
70
+
71
+ def verify_mocks_for_rspec
72
+ Expector.verify_expectors.each {|d| d.verify}
73
+ end
74
+
75
+ def teardown_mocks_for_rspec
76
+ Expector.clear_expectors
77
+ end
78
+ end
79
+ end
80
+ """
81
+
82
+ Given a file named "example_spec.rb" with:
83
+ """
84
+ require File.expand_path("../expector", __FILE__)
85
+
86
+ RSpec.configure do |config|
87
+ config.mock_framework = Expector::RSpecAdapter
88
+ end
89
+
90
+ describe Expector do
91
+ it "passes when message is received" do
92
+ expector = Expector.new
93
+ expector.expect(:foo)
94
+ expector.foo
95
+ end
96
+
97
+ it "fails when message is received" do
98
+ expector = Expector.new
99
+ expector.expect(:foo)
100
+ end
101
+ end
102
+ """
103
+ When I run "rspec example_spec.rb --format doc"
104
+ Then the exit status should be 1
105
+ And the output should contain "2 examples, 1 failure"
106
+ And the output should contain "fails when message is received (FAILED - 1)"
@@ -9,3 +9,8 @@ Then /^the output should not contain any of these:$/ do |table|
9
9
  combined_output.should_not =~ compile_and_escape(string)
10
10
  end
11
11
  end
12
+
13
+ Then /^the example(s)? should( all)? pass$/ do |*|
14
+ Then %q{the output should contain "0 failures"}
15
+ Then %q{the exit status should be 0}
16
+ end
@@ -60,3 +60,19 @@ Feature: explicit subject
60
60
  """
61
61
  When I run "rspec helper_subject_spec.rb"
62
62
  Then the output should contain "1 example, 0 failures"
63
+
64
+ Scenario: subject block is invoked at most once per example
65
+ Given a file named "nil_subject_spec.rb" with:
66
+ """
67
+ describe Array do
68
+ describe "#[]" do
69
+ context "with index out of bounds" do
70
+ before { Array.should_receive(:one_two_three).once.and_return([1,2,3]) }
71
+ subject { Array.one_two_three[42] }
72
+ it { should be_nil }
73
+ end
74
+ end
75
+ end
76
+ """
77
+ When I run "rspec nil_subject_spec.rb"
78
+ Then the output should contain "1 example, 0 failures"
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" } if File.exist?("./.rspec")
@@ -19,6 +19,7 @@ require 'rspec/core/command_line'
19
19
  require 'rspec/core/drb_command_line'
20
20
  require 'rspec/core/runner'
21
21
  require 'rspec/core/example'
22
+ require 'rspec/core/shared_context'
22
23
  require 'rspec/core/shared_example_group'
23
24
  require 'rspec/core/example_group'
24
25
  require 'rspec/core/version'
@@ -27,6 +28,8 @@ require 'rspec/core/errors'
27
28
  module RSpec
28
29
  autoload :Matchers, 'rspec/matchers'
29
30
 
31
+ SharedContext = Core::SharedContext
32
+
30
33
  module Core
31
34
  def self.install_directory
32
35
  @install_directory ||= File.expand_path(File.dirname(__FILE__))
@@ -26,8 +26,6 @@ module RSpec
26
26
  add_setting :profile_examples
27
27
  add_setting :fail_fast, :default => false
28
28
  add_setting :run_all_when_everything_filtered
29
- add_setting :mock_framework, :default => :rspec
30
- add_setting :expectation_framework, :default => :rspec
31
29
  add_setting :filter
32
30
  add_setting :exclusion_filter
33
31
  add_setting :filename_pattern, :default => '**/*_spec.rb'
@@ -112,35 +110,98 @@ module RSpec
112
110
  backtrace_clean_patterns.any? { |regex| line =~ regex }
113
111
  end
114
112
 
115
- def mock_with(mock_framework)
116
- settings[:mock_framework] = mock_framework
113
+ # Returns the configured mock framework adapter module
114
+ def mock_framework
115
+ settings[:mock_framework] ||= begin
116
+ require 'rspec/core/mocking/with_rspec'
117
+ RSpec::Core::MockFrameworkAdapter
118
+ end
117
119
  end
118
120
 
119
- def require_mock_framework_adapter
120
- require case mock_framework.to_s
121
- when /rspec/i
122
- 'rspec/core/mocking/with_rspec'
123
- when /mocha/i
124
- 'rspec/core/mocking/with_mocha'
125
- when /rr/i
126
- 'rspec/core/mocking/with_rr'
127
- when /flexmock/i
128
- 'rspec/core/mocking/with_flexmock'
121
+ # Delegates to mock_framework=(framework)
122
+ def mock_with(framework)
123
+ self.mock_framework = framework
124
+ end
125
+
126
+ # Sets the mock framework adapter module.
127
+ #
128
+ # +framework+ can be a Symbol or a Module.
129
+ #
130
+ # Given any of :rspec, :mocha, :flexmock, or :rr, configures the named
131
+ # framework.
132
+ #
133
+ # Given :nothing, configures no framework. Use this if you don't use any
134
+ # mocking framework to save a little bit of overhead.
135
+ #
136
+ # Given a Module, includes that module in every example group. The module
137
+ # should adhere to RSpec's mock framework adapter API:
138
+ #
139
+ # setup_mocks_for_rspec
140
+ # - called before each example
141
+ #
142
+ # verify_mocks_for_rspec
143
+ # - called after each example. Framework should raise an exception
144
+ # when expectations fail
145
+ #
146
+ # teardown_mocks_for_rspec
147
+ # - called after verify_mocks_for_rspec (even if there are errors)
148
+ def mock_framework=(framework)
149
+ case framework
150
+ when Module
151
+ settings[:mock_framework] = framework
152
+ when String, Symbol
153
+ require case framework.to_s
154
+ when /rspec/i
155
+ 'rspec/core/mocking/with_rspec'
156
+ when /mocha/i
157
+ 'rspec/core/mocking/with_mocha'
158
+ when /rr/i
159
+ 'rspec/core/mocking/with_rr'
160
+ when /flexmock/i
161
+ 'rspec/core/mocking/with_flexmock'
162
+ else
163
+ 'rspec/core/mocking/with_absolutely_nothing'
164
+ end
165
+ settings[:mock_framework] = RSpec::Core::MockFrameworkAdapter
129
166
  else
130
- 'rspec/core/mocking/with_absolutely_nothing'
131
167
  end
132
168
  end
133
169
 
134
- def expect_with(expectation_framework)
135
- settings[:expectation_framework] = expectation_framework
170
+ # Returns the configured expectation framework adapter module(s)
171
+ def expectation_frameworks
172
+ settings[:expectation_frameworks] ||= begin
173
+ require 'rspec/core/expecting/with_rspec'
174
+ [RSpec::Core::ExpectationFrameworkAdapter]
175
+ end
136
176
  end
137
177
 
138
- def require_expectation_framework_adapter
139
- require case expectation_framework.to_s
140
- when /rspec/i
141
- 'rspec/core/expecting/with_rspec'
142
- else
143
- raise ArgumentError, "#{expectation_framework.inspect} is not supported"
178
+ # Delegates to expect_with=([framework])
179
+ def expectation_framework=(framework)
180
+ expect_with([framework])
181
+ end
182
+
183
+ # Sets the expectation framework module(s).
184
+ #
185
+ # +frameworks+ can be :rspec, :stdlib, or both
186
+ #
187
+ # Given :rspec, configures rspec/expectations.
188
+ # Given :stdlib, configures test/unit/assertions
189
+ # Given both, configures both
190
+ def expect_with(*frameworks)
191
+ settings[:expectation_frameworks] = []
192
+ frameworks.each do |framework|
193
+ case framework
194
+ when Symbol
195
+ case framework
196
+ when :rspec
197
+ require 'rspec/core/expecting/with_rspec'
198
+ when :stdlib
199
+ require 'rspec/core/expecting/with_stdlib'
200
+ else
201
+ raise ArgumentError, "#{framework.inspect} is not supported"
202
+ end
203
+ settings[:expectation_frameworks] << RSpec::Core::ExpectationFrameworkAdapter
204
+ end
144
205
  end
145
206
  end
146
207
 
@@ -314,13 +375,13 @@ EOM
314
375
  end
315
376
 
316
377
  def configure_mock_framework
317
- require_mock_framework_adapter
318
- RSpec::Core::ExampleGroup.send(:include, RSpec::Core::MockFrameworkAdapter)
378
+ RSpec::Core::ExampleGroup.send(:include, mock_framework)
319
379
  end
320
380
 
321
381
  def configure_expectation_framework
322
- require_expectation_framework_adapter
323
- RSpec::Core::ExampleGroup.send(:include, RSpec::Core::ExpectationFrameworkAdapter)
382
+ expectation_frameworks.each do |framework|
383
+ RSpec::Core::ExampleGroup.send(:include, framework)
384
+ end
324
385
  end
325
386
 
326
387
  def load_spec_files
@@ -346,8 +407,6 @@ MESSAGE
346
407
  end
347
408
  end
348
409
 
349
- private
350
-
351
410
  def output_to_tty?
352
411
  begin
353
412
  output_stream.tty? || tty?
@@ -177,8 +177,8 @@ module RSpec
177
177
  store_before_all_ivars(example_group_instance)
178
178
  end
179
179
 
180
- def self.eval_around_eachs(example_group_instance, procsy)
181
- around_hooks.reverse.inject(procsy) do |procsy, around_hook|
180
+ def self.eval_around_eachs(example_group_instance, initial_procsy)
181
+ around_hooks.reverse.inject(initial_procsy) do |procsy, around_hook|
182
182
  Example::Procsy.new(procsy.metadata) do
183
183
  example_group_instance.instance_eval_with_args(procsy, &around_hook)
184
184
  end
@@ -0,0 +1,9 @@
1
+ require 'test/unit/assertions'
2
+
3
+ module RSpec
4
+ module Core
5
+ module ExpectationFrameworkAdapter
6
+ include Test::Unit::Assertions
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module RSpec
2
+ module Core
3
+ module SharedContext
4
+ include Hooks
5
+
6
+ def included(group)
7
+ [:before, :after].each do |type|
8
+ [:all, :each].each do |scope|
9
+ group.hooks[type][scope].concat hooks[type][scope]
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -7,6 +7,8 @@ module RSpec
7
7
  RSpec.world.shared_example_groups[name] = block
8
8
  end
9
9
 
10
+ alias :shared_examples_for :share_examples_for
11
+
10
12
  def share_as(name, &block)
11
13
  if Object.const_defined?(name)
12
14
  mod = Object.const_get(name)
@@ -31,7 +33,6 @@ module RSpec
31
33
  RSpec.world.shared_example_groups[shared_const] = block
32
34
  end
33
35
 
34
- alias :shared_examples_for :share_examples_for
35
36
 
36
37
  private
37
38
 
@@ -28,7 +28,11 @@ module RSpec
28
28
  # end
29
29
  # end
30
30
  def subject
31
- @original_subject ||= instance_eval(&self.class.subject)
31
+ if defined?(@original_subject)
32
+ @original_subject
33
+ else
34
+ @original_subject = instance_eval(&self.class.subject)
35
+ end
32
36
  end
33
37
 
34
38
  begin
@@ -86,7 +90,7 @@ module RSpec
86
90
  # The attribute can be a +Symbol+ or a +String+. Given a +String+
87
91
  # with dots, the result is as though you concatenated that +String+
88
92
  # onto the subject in an expression.
89
- #
93
+ #
90
94
  # describe Person do
91
95
  # subject do
92
96
  # Person.new.tap do |person|
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Core # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.2.1'
4
+ STRING = '2.3.0'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe "autotest/discover.rb" do
4
+ context "with /.rspec present" do
5
+ it "adds 'rspec2' to the list of discoveries" do
6
+ File.stub(:exist?).with("./.rspec") { true }
7
+ Autotest.should_receive(:add_discovery)
8
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
9
+ end
10
+ end
11
+
12
+ context "with /.rspec absent" do
13
+ it "does not add 'rspec2' to the list of discoveries" do
14
+ File.stub(:exist?) { false }
15
+ Autotest.should_not_receive(:add_discovery)
16
+ load File.expand_path("../../../lib/autotest/discover.rb", __FILE__)
17
+ end
18
+ end
19
+ end
@@ -29,64 +29,74 @@ module RSpec::Core
29
29
  end
30
30
  end
31
31
 
32
- describe "mock_framework" do
33
- before(:each) do
34
- config.stub(:require)
35
- end
36
-
32
+ describe "#mock_framework" do
37
33
  it "defaults to :rspec" do
38
34
  config.should_receive(:require).with('rspec/core/mocking/with_rspec')
39
- config.require_mock_framework_adapter
35
+ config.mock_framework
40
36
  end
37
+ end
41
38
 
39
+ describe "#mock_framework=" do
42
40
  [:rspec, :mocha, :rr, :flexmock].each do |framework|
43
- it "uses #{framework.inspect} framework when set explicitly" do
44
- config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
45
- config.mock_framework = framework
46
- config.require_mock_framework_adapter
41
+ context "with #{framework}" do
42
+ it "requires the adapter for #{framework.inspect}" do
43
+ config.should_receive(:require).with("rspec/core/mocking/with_#{framework}")
44
+ config.mock_framework = framework
45
+ end
46
+ end
47
+ end
48
+
49
+ context "with a module" do
50
+ it "sets the mock_framework_adapter to that module" do
51
+ config.stub(:require)
52
+ mod = Module.new
53
+ config.mock_framework = mod
54
+ config.mock_framework.should eq(mod)
47
55
  end
48
56
  end
49
57
 
50
58
  it "uses the null adapter when set to any unknown key" do
51
59
  config.should_receive(:require).with('rspec/core/mocking/with_absolutely_nothing')
52
60
  config.mock_framework = :crazy_new_mocking_framework_ive_not_yet_heard_of
53
- config.require_mock_framework_adapter
54
61
  end
62
+ end
55
63
 
56
- it "supports mock_with for backward compatibility with rspec-1.x" do
57
- config.should_receive(:require).with('rspec/core/mocking/with_rspec')
64
+ describe "#mock_with" do
65
+ it "delegates to mock_framework=" do
66
+ config.should_receive(:mock_framework=).with(:rspec)
58
67
  config.mock_with :rspec
59
- config.require_mock_framework_adapter
60
68
  end
61
-
62
69
  end
63
70
 
64
- describe "expectation_framework" do
65
-
71
+ describe "#expectation_framework" do
66
72
  it "defaults to :rspec" do
67
73
  config.should_receive(:require).with('rspec/core/expecting/with_rspec')
68
- config.require_expectation_framework_adapter
74
+ config.expectation_frameworks
69
75
  end
76
+ end
70
77
 
71
- [:rspec].each do |framework|
72
- it "uses #{framework.inspect} framework when set explicitly" do
73
- config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
74
- config.mock_framework = framework
75
- config.require_expectation_framework_adapter
76
- end
78
+ describe "#expectation_framework=" do
79
+ it "delegates to expect_with=" do
80
+ config.should_receive(:expect_with).with([:rspec])
81
+ config.expectation_framework = :rspec
77
82
  end
83
+ end
78
84
 
79
- it "supports expect_with for backward compatibility with rspec-1.x" do
80
- config.should_receive(:require).with('rspec/core/expecting/with_rspec')
81
- config.mock_with :rspec
82
- config.require_expectation_framework_adapter
85
+ describe "#expect_with" do
86
+ [:rspec, :stdlib].each do |framework|
87
+ context "with #{framework}" do
88
+ it "requires the adapter for #{framework.inspect}" do
89
+ config.should_receive(:require).with("rspec/core/expecting/with_#{framework}")
90
+ config.expect_with framework
91
+ end
92
+ end
83
93
  end
84
94
 
85
95
  it "raises ArgumentError if framework is not supported" do
86
- config.expectation_framework = :not_supported
87
- expect { config.require_expectation_framework_adapter }.to raise_error(ArgumentError)
96
+ expect do
97
+ config.expect_with :not_supported
98
+ end.to raise_error(ArgumentError)
88
99
  end
89
-
90
100
  end
91
101
 
92
102
  context "setting the files to run" do
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe RSpec::Core::SharedContext do
4
+ describe "hooks" do
5
+ it "creates a before hook" do
6
+ before_all_hook = false
7
+ before_each_hook = false
8
+ after_each_hook = false
9
+ after_all_hook = false
10
+ shared = Module.new do
11
+ extend RSpec::Core::SharedContext
12
+ before(:all) { before_all_hook = true }
13
+ before(:each) { before_each_hook = true }
14
+ after(:each) { after_each_hook = true }
15
+ after(:all) { after_all_hook = true }
16
+ end
17
+ group = RSpec::Core::ExampleGroup.describe do
18
+ include shared
19
+ example { }
20
+ end
21
+
22
+ group.run
23
+
24
+ before_all_hook.should be_true
25
+ before_each_hook.should be_true
26
+ after_each_hook.should be_true
27
+ after_all_hook.should be_true
28
+ end
29
+ end
30
+ end
@@ -32,6 +32,25 @@ module RSpec::Core
32
32
  end
33
33
 
34
34
  describe "explicit subject" do
35
+ [false, nil].each do |falsy_value|
36
+ context "with a value of #{falsy_value.inspect}" do
37
+ it "is evaluated once per example" do
38
+ group = ExampleGroup.describe(Array)
39
+ group.before do
40
+ Object.should_receive(:this_question?).once.and_return(falsy_value)
41
+ end
42
+ group.subject do
43
+ Object.this_question?
44
+ end
45
+ group.example do
46
+ subject
47
+ subject
48
+ end
49
+ group.run.should be_true, "expected subject block to be evaluated only once"
50
+ end
51
+ end
52
+ end
53
+
35
54
  describe "defined in a top level group" do
36
55
  it "replaces the implicit subject in that group" do
37
56
  group = ExampleGroup.describe(Array)
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-core
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 2
8
- - 1
9
- version: 2.2.1
8
+ - 3
9
+ - 0
10
+ version: 2.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Chad Humphries
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-11-28 00:00:00 -06:00
19
+ date: 2010-12-12 00:00:00 -06:00
19
20
  default_executable: rspec
20
21
  dependencies: []
21
22
 
@@ -31,6 +32,7 @@ extra_rdoc_files:
31
32
  files:
32
33
  - .document
33
34
  - .gitignore
35
+ - .rspec
34
36
  - Gemfile
35
37
  - Guardfile
36
38
  - History.markdown
@@ -38,7 +40,6 @@ files:
38
40
  - README.md
39
41
  - Rakefile
40
42
  - Upgrade.markdown
41
- - autotest/discover.rb
42
43
  - bin/autospec
43
44
  - bin/rspec
44
45
  - cucumber.yml
@@ -55,6 +56,7 @@ files:
55
56
  - features/configuration/read_options_from_file.feature
56
57
  - features/example_groups/basic_structure.feature
57
58
  - features/example_groups/shared_example_group.feature
59
+ - features/expectation_framework_integration/configure_expectation_framework.feature
58
60
  - features/filtering/exclusion_filters.feature
59
61
  - features/filtering/implicit_filters.feature
60
62
  - features/filtering/inclusion_filters.feature
@@ -63,6 +65,7 @@ files:
63
65
  - features/hooks/around_hooks.feature
64
66
  - features/hooks/before_and_after_hooks.feature
65
67
  - features/metadata/described_class.feature
68
+ - features/mock_framework_integration/use_any_framework.feature
66
69
  - features/mock_framework_integration/use_flexmock.feature
67
70
  - features/mock_framework_integration/use_mocha.feature
68
71
  - features/mock_framework_integration/use_rr.feature
@@ -75,6 +78,7 @@ files:
75
78
  - features/subject/implicit_receiver.feature
76
79
  - features/subject/implicit_subject.feature
77
80
  - features/support/env.rb
81
+ - lib/autotest/discover.rb
78
82
  - lib/autotest/rspec2.rb
79
83
  - lib/rspec/autorun.rb
80
84
  - lib/rspec/core.rb
@@ -89,6 +93,7 @@ files:
89
93
  - lib/rspec/core/example.rb
90
94
  - lib/rspec/core/example_group.rb
91
95
  - lib/rspec/core/expecting/with_rspec.rb
96
+ - lib/rspec/core/expecting/with_stdlib.rb
92
97
  - lib/rspec/core/extensions.rb
93
98
  - lib/rspec/core/extensions/instance_eval_with_args.rb
94
99
  - lib/rspec/core/extensions/kernel.rb
@@ -117,6 +122,7 @@ files:
117
122
  - lib/rspec/core/reporter.rb
118
123
  - lib/rspec/core/ruby_project.rb
119
124
  - lib/rspec/core/runner.rb
125
+ - lib/rspec/core/shared_context.rb
120
126
  - lib/rspec/core/shared_example_group.rb
121
127
  - lib/rspec/core/subject.rb
122
128
  - lib/rspec/core/version.rb
@@ -125,6 +131,7 @@ files:
125
131
  - lib/rspec/monkey/spork/test_framework/rspec.rb
126
132
  - rspec-core.gemspec
127
133
  - script/console
134
+ - spec/autotest/discover_spec.rb
128
135
  - spec/autotest/failed_results_re_spec.rb
129
136
  - spec/autotest/rspec_spec.rb
130
137
  - spec/rspec/core/command_line_configuration_spec.rb
@@ -171,6 +178,7 @@ files:
171
178
  - spec/rspec/core/resources/utf8_encoded.rb
172
179
  - spec/rspec/core/ruby_project_spec.rb
173
180
  - spec/rspec/core/runner_spec.rb
181
+ - spec/rspec/core/shared_context_spec.rb
174
182
  - spec/rspec/core/shared_example_group_spec.rb
175
183
  - spec/rspec/core/subject_spec.rb
176
184
  - spec/rspec/core/world_spec.rb
@@ -185,7 +193,7 @@ licenses: []
185
193
  post_install_message: |
186
194
  **************************************************
187
195
 
188
- Thank you for installing rspec-core-2.2.1
196
+ Thank you for installing rspec-core-2.3.0
189
197
 
190
198
  Please be sure to look at the upgrade instructions to see what might have
191
199
  changed since the last release:
@@ -203,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
211
  requirements:
204
212
  - - ">="
205
213
  - !ruby/object:Gem::Version
206
- hash: 1903527801491701524
214
+ hash: 3
207
215
  segments:
208
216
  - 0
209
217
  version: "0"
@@ -212,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
220
  requirements:
213
221
  - - ">="
214
222
  - !ruby/object:Gem::Version
215
- hash: 1903527801491701524
223
+ hash: 3
216
224
  segments:
217
225
  - 0
218
226
  version: "0"
@@ -222,7 +230,7 @@ rubyforge_project: rspec
222
230
  rubygems_version: 1.3.7
223
231
  signing_key:
224
232
  specification_version: 3
225
- summary: rspec-core-2.2.1
233
+ summary: rspec-core-2.3.0
226
234
  test_files:
227
235
  - features/README.markdown
228
236
  - features/command_line/configure.feature
@@ -237,6 +245,7 @@ test_files:
237
245
  - features/configuration/read_options_from_file.feature
238
246
  - features/example_groups/basic_structure.feature
239
247
  - features/example_groups/shared_example_group.feature
248
+ - features/expectation_framework_integration/configure_expectation_framework.feature
240
249
  - features/filtering/exclusion_filters.feature
241
250
  - features/filtering/implicit_filters.feature
242
251
  - features/filtering/inclusion_filters.feature
@@ -245,6 +254,7 @@ test_files:
245
254
  - features/hooks/around_hooks.feature
246
255
  - features/hooks/before_and_after_hooks.feature
247
256
  - features/metadata/described_class.feature
257
+ - features/mock_framework_integration/use_any_framework.feature
248
258
  - features/mock_framework_integration/use_flexmock.feature
249
259
  - features/mock_framework_integration/use_mocha.feature
250
260
  - features/mock_framework_integration/use_rr.feature
@@ -257,6 +267,7 @@ test_files:
257
267
  - features/subject/implicit_receiver.feature
258
268
  - features/subject/implicit_subject.feature
259
269
  - features/support/env.rb
270
+ - spec/autotest/discover_spec.rb
260
271
  - spec/autotest/failed_results_re_spec.rb
261
272
  - spec/autotest/rspec_spec.rb
262
273
  - spec/rspec/core/command_line_configuration_spec.rb
@@ -303,6 +314,7 @@ test_files:
303
314
  - spec/rspec/core/resources/utf8_encoded.rb
304
315
  - spec/rspec/core/ruby_project_spec.rb
305
316
  - spec/rspec/core/runner_spec.rb
317
+ - spec/rspec/core/shared_context_spec.rb
306
318
  - spec/rspec/core/shared_example_group_spec.rb
307
319
  - spec/rspec/core/subject_spec.rb
308
320
  - spec/rspec/core/world_spec.rb
@@ -1,2 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
2
-