rspec-core 2.0.0.a1 → 2.0.0.a2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/README.markdown +34 -3
  2. data/Rakefile +32 -17
  3. data/bin/rspec +5 -7
  4. data/cucumber.yml +3 -2
  5. data/features-pending/example_groups/example_group_with_should_methods.feature +3 -1
  6. data/features/before_and_after_blocks/around.feature +34 -0
  7. data/features/example_groups/describe_aliases.feature +20 -0
  8. data/{features-pending → features}/example_groups/nested_groups.feature +6 -8
  9. data/features/expectations/customized_message.feature +6 -6
  10. data/{features-pending → features}/matchers/define_matcher.feature +9 -9
  11. data/features/mock_framework_integration/use_rspec.feature +1 -1
  12. data/features/mocks/block_local_expectations.feature +68 -0
  13. data/{features-pending → features}/mocks/mix_stubs_and_mocks.feature +5 -1
  14. data/features/support/env.rb +6 -18
  15. data/lib/rspec/core.rb +5 -5
  16. data/lib/rspec/core/advice.rb +49 -0
  17. data/lib/rspec/core/command_line_options.rb +4 -11
  18. data/lib/rspec/core/configuration.rb +20 -32
  19. data/lib/rspec/core/example.rb +48 -15
  20. data/lib/rspec/core/example_group.rb +68 -93
  21. data/lib/rspec/core/extensions/instance_exec.rb +31 -0
  22. data/lib/rspec/core/kernel_extensions.rb +3 -1
  23. data/lib/rspec/core/load_path.rb +4 -0
  24. data/lib/rspec/core/metadata.rb +78 -0
  25. data/lib/rspec/core/rake_task.rb +3 -4
  26. data/lib/rspec/core/ruby_project.rb +30 -0
  27. data/lib/rspec/core/runner.rb +6 -7
  28. data/lib/rspec/core/version.rb +2 -2
  29. data/lib/rspec/core/world.rb +6 -4
  30. data/rspec-core.gemspec +33 -14
  31. data/spec/rspec/core/command_line_options_spec.rb +10 -10
  32. data/spec/rspec/core/configuration_spec.rb +26 -21
  33. data/spec/rspec/core/example_group_spec.rb +243 -173
  34. data/spec/rspec/core/example_group_subject_spec.rb +1 -1
  35. data/spec/rspec/core/example_spec.rb +12 -22
  36. data/spec/rspec/core/formatters/base_formatter_spec.rb +1 -1
  37. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +1 -1
  38. data/spec/rspec/core/formatters/progress_formatter_spec.rb +4 -3
  39. data/spec/rspec/core/kernel_extensions_spec.rb +1 -1
  40. data/spec/rspec/core/metadata_spec.rb +101 -0
  41. data/spec/rspec/core/mocha_spec.rb +2 -2
  42. data/spec/rspec/core/runner_spec.rb +5 -5
  43. data/spec/rspec/core/shared_behaviour_spec.rb +5 -5
  44. data/spec/rspec/core/world_spec.rb +8 -8
  45. data/spec/rspec/core_spec.rb +1 -1
  46. data/spec/spec_helper.rb +15 -8
  47. data/specs.watchr +57 -0
  48. metadata +53 -15
  49. data/VERSION +0 -1
  50. data/VERSION.yml +0 -5
@@ -2,8 +2,39 @@
2
2
 
3
3
  See README.markdown at [http://github.com/rspec/meta](http://github.com/rspec/meta)
4
4
 
5
-
6
5
  #### Also see
7
6
 
8
- * [http://github.com/rspec/expectations](http://github.com/rspec/expectations)
9
- * [http://github.com/rspec/mocks](http://github.com/rspec/mocks)
7
+ * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
8
+ * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
9
+
10
+ ## Known Issues
11
+
12
+ ### Ruby-1.9
13
+
14
+ Due to changes in scoping rules in 1.9, classes defined inside example groups
15
+ are not visible to the examples. For example:
16
+
17
+ describe "something" do
18
+ class Foo
19
+ end
20
+
21
+ it "does something" do
22
+ Foo.new
23
+ end
24
+ end
25
+
26
+ This runs without incident in ruby-1.8, but raises an `uninitialized constant`
27
+ error in ruby-1.9. We had solved this in rspec-1.x, but rspec-2 has a slightly
28
+ different object model, so this has (for the moment) reared its ugly head. We'll
29
+ certainly resolve this before rspec-core-2.0.0 (final) is released.
30
+
31
+ You can, of course, fully qualify the declaration and everything works fine:
32
+
33
+ describe "something" do
34
+ class ::Foo
35
+ end
36
+
37
+ it "does something" do
38
+ Foo.new
39
+ end
40
+ end
data/Rakefile CHANGED
@@ -1,45 +1,60 @@
1
1
  require 'rubygems'
2
+ gem "jeweler", ">= 1.4.0"
2
3
  require 'rake'
3
4
  require 'yaml'
4
5
 
5
- $:.unshift 'lib'
6
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__),'lib'))
6
7
 
7
8
  require 'rake/rdoctask'
8
9
  require 'rspec/core/rake_task'
10
+ require 'rspec/core/version'
9
11
  require 'cucumber/rake/task'
10
12
 
11
13
  begin
12
14
  require 'jeweler'
13
15
  Jeweler::Tasks.new do |gem|
14
16
  gem.name = "rspec-core"
15
- gem.summary = "RSpec Core"
16
- gem.description = 'RSpec Core'
17
+ gem.version = Rspec::Core::Version::STRING
18
+ gem.rubyforge_project = "rspec"
19
+ gem.summary = 'Rspec runner and example group classes'
17
20
  gem.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
18
21
  gem.homepage = "http://github.com/rspec/core"
19
22
  gem.authors = ["David Chelimsky", "Chad Humphries"]
20
- gem.add_development_dependency('rspec-expectations', '>= 2.0.0.a1')
21
- gem.add_development_dependency('rspec-mocks', '>= 2.0.0.a1')
23
+ gem.version = Rspec::Core::Version::STRING
24
+ gem.add_development_dependency "rspec-expectations", ">= #{Rspec::Core::Version::STRING}"
25
+ gem.add_development_dependency "rspec-mocks", ">= #{Rspec::Core::Version::STRING}"
26
+ gem.add_development_dependency('cucumber', '>= 0.5.3')
22
27
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
28
  end
29
+ Jeweler::GemcutterTasks.new
24
30
  rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
31
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
32
  end
27
33
 
28
- Rspec::Core::RakeTask.new :spec do |t|
29
- t.ruby_opts = %[-Ilib -Ispec]
30
- t.pattern = "spec/**/*_spec.rb"
34
+ begin
35
+ Rspec::Core::RakeTask.new :spec do |t|
36
+ t.pattern = "spec/**/*_spec.rb"
37
+ end
38
+
39
+ desc "Run all examples using rcov"
40
+ Rspec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
41
+ t.rcov = true
42
+ t.rcov_opts = %[-Ilib -Ispec --exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*"]
43
+ t.rcov_opts << %[--no-html --aggregate coverage.data]
44
+ t.pattern = "spec/**/*_spec.rb"
45
+ end
46
+ rescue LoadError
47
+ puts "Rspec core or one of its dependencies is not installed. Install it with: gem install rspec-meta"
31
48
  end
32
49
 
33
50
  task :cleanup_rcov_files do
34
51
  rm_rf 'coverage.data'
35
52
  end
36
53
 
37
- desc "Run all examples using rcov"
38
- Rspec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
39
- t.rcov = true
40
- t.rcov_opts = %[-Ilib -Ispec --exclude "mocks,expectations,gems/*,spec/resources,spec/lib,spec/spec_helper.rb,db/*,/Library/Ruby/*,config/*"]
41
- t.rcov_opts << %[--no-html --aggregate coverage.data]
42
- t.pattern = "spec/**/*_spec.rb"
54
+ task :clobber do
55
+ rm_rf 'pkg'
56
+ rm_rf 'tmp'
57
+ rm_rf 'coverage'
43
58
  end
44
59
 
45
60
  if RUBY_VERSION == '1.9.1'
@@ -47,7 +62,7 @@ if RUBY_VERSION == '1.9.1'
47
62
  t.cucumber_opts = %w{--format progress}
48
63
  end
49
64
 
50
- task :default => [:spec, :features]
65
+ task :default => [:check_dependencies, :spec, :features]
51
66
  else
52
67
  Cucumber::Rake::Task.new :features do |t|
53
68
  t.rcov = true
@@ -56,7 +71,7 @@ else
56
71
  t.cucumber_opts = %w{--format progress}
57
72
  end
58
73
 
59
- task :default => [:rcov, :features]
74
+ task :default => [:check_dependencies, :rcov, :features]
60
75
  end
61
76
 
62
77
 
data/bin/rspec CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # Temporary, until things are actually gems
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../expectations/lib'))
2
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
3
+ $LOAD_PATH.unshift(File.expand_path('../../../rspec-expectations/lib', __FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../../../rspec-mocks/lib', __FILE__))
4
5
  require 'rspec/expectations'
5
-
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../mocks/lib'))
7
6
  require 'rspec/mocks'
8
-
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
7
  require 'rspec/autorun'
11
8
 
12
- Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
9
+ # TODO - this feels odd here - move to runner?
10
+ Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
@@ -1,2 +1,3 @@
1
- default: features -r features -t ~wip
2
- wip: features -r features -t wip
1
+ default: features -r features -t ~@wip
2
+ wip: features -r features -t @wip
3
+ all: features -r features
@@ -8,8 +8,10 @@ Feature: Spec::ExampleGroup with should methods
8
8
  Given a file named "example_group_with_should_methods.rb" with:
9
9
  """
10
10
  require 'rspec/autorun'
11
+ require 'rspec/expectations'
12
+ Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
11
13
 
12
- class MySpec < Spec::ExampleGroup
14
+ class MySpec < Rspec::Core::ExampleGroup
13
15
  def should_pass_with_should
14
16
  1.should == 1
15
17
  end
@@ -0,0 +1,34 @@
1
+ Feature: before and after blocks
2
+
3
+ Scenario: define around(:each) block in example group
4
+ Given a file named "around_each_in_example_group_spec.rb" with:
5
+ """
6
+ class Thing
7
+ def self.cache
8
+ @cache ||= []
9
+ end
10
+
11
+ def initialize
12
+ self.class.cache << self
13
+ end
14
+ end
15
+
16
+ describe Thing do
17
+ around(:each) do |example|
18
+ Thing.new
19
+ example.run
20
+ Thing.cache.clear
21
+ end
22
+
23
+ it "has 1 Thing (1)" do
24
+ Thing.cache.length.should == 1
25
+ end
26
+
27
+ it "has 1 Thing (2)" do
28
+ Thing.cache.length.should == 1
29
+ end
30
+ end
31
+ """
32
+ When I run "rspec around_each_in_example_group_spec.rb"
33
+ Then the stderr should not match "NoMethodError"
34
+ Then the stdout should match "2 examples, 0 failures"
@@ -0,0 +1,20 @@
1
+ Feature: Nested example groups
2
+
3
+ As an RSpec user
4
+ I want to use alternate names for describe
5
+ So that I can better organize my examples
6
+
7
+ Scenario Outline: Using context
8
+ Given a file named "context_instead_of_describe_spec.rb" with:
9
+ """
10
+ context "Using context" do
11
+ context "with nested context" do
12
+ it "should do this" do
13
+ true.should be_true
14
+ end
15
+ end
16
+ end
17
+ """
18
+ When I run "rspec context_instead_of_describe_spec.rb -fn"
19
+ Then the stdout should match /^Using context/
20
+ And the stdout should match /^\s+with nested context/
@@ -8,6 +8,8 @@ Feature: Nested example groups
8
8
  Given a file named "nested_example_groups.rb" with:
9
9
  """
10
10
  require 'rspec/autorun'
11
+ require 'rspec/expectations'
12
+ Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
11
13
 
12
14
  describe "Some Object" do
13
15
  describe "with some more context" do
@@ -22,11 +24,7 @@ Feature: Nested example groups
22
24
  end
23
25
  end
24
26
  """
25
- When I run "<Command> nested_example_groups.rb -fs"
26
- Then the stdout should match /Some Object with some more context/
27
- And the stdout should match /Some Object with some other context/
28
-
29
- Scenarios: Run with ruby and spec
30
- | Command |
31
- | ruby |
32
- | spec |
27
+ When I run "rspec nested_example_groups.rb -fn"
28
+ Then the stdout should match /^Some Object/
29
+ And the stdout should match /^\s+with some more context/
30
+ And the stdout should match /^\s+with some other context/
@@ -5,7 +5,7 @@ Feature: customized message
5
5
  I want to customize the failure message per example
6
6
 
7
7
  Scenario: one additional method
8
- Given a file named "node_spec.rb.rb" with:
8
+ Given a file named "node_spec.rb" with:
9
9
  """
10
10
  class Node
11
11
  def initialize(state=:waiting)
@@ -24,28 +24,28 @@ Feature: customized message
24
24
  @state = :started
25
25
  end
26
26
  end
27
-
27
+
28
28
  describe "a new Node" do
29
29
  it "should be waiting" do
30
30
  node = Node.new(:started) #start w/ started to trigger failure
31
31
  node.should be_waiting, "node.state: #{node.state} (first example)"
32
32
  end
33
-
33
+
34
34
  it "should not be started" do
35
35
  node = Node.new(:started) #start w/ started to trigger failure
36
36
  node.should_not be_started, "node.state: #{node.state} (second example)"
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe "node.start" do
41
41
  it "should change the state" do
42
42
  node = Node.new(:started) #start w/ started to trigger failure
43
43
  lambda {node.start}.should change{node.state}, "expected a change"
44
44
  end
45
45
  end
46
-
46
+
47
47
  """
48
- When I run "spec node_spec.rb.rb --format specdoc"
48
+ When I run "rspec node_spec.rb --format n"
49
49
  Then the stdout should match "3 examples, 3 failures"
50
50
  And the stdout should not match "to return true, got false"
51
51
  And the stdout should not match "to return false, got true"
@@ -32,13 +32,13 @@ Feature: define matcher
32
32
  end
33
33
 
34
34
  """
35
- When I run "spec matcher_with_default_message_spec.rb --format specdoc"
35
+ When I run "rspec matcher_with_default_message_spec.rb --format specdoc"
36
36
  Then the exit code should be 256
37
37
 
38
38
  And the stdout should match "should be a multiple of 3"
39
39
  And the stdout should match "should not be a multiple of 4"
40
- And the stdout should match "should be a multiple of 4 (FAILED - 1)"
41
- And the stdout should match "should not be a multiple of 3 (FAILED - 2)"
40
+ And the stdout should match "should be a multiple of 4\n Failure"
41
+ And the stdout should match "should not be a multiple of 3\n Failure"
42
42
 
43
43
  And the stdout should match "4 examples, 2 failures"
44
44
  And the stdout should match "expected 9 to be a multiple of 4"
@@ -61,7 +61,7 @@ Feature: define matcher
61
61
  it {should be_a_multiple_of(4)}
62
62
  end
63
63
  """
64
- When I run "spec matcher_with_failure_message_spec.rb"
64
+ When I run "rspec matcher_with_failure_message_spec.rb"
65
65
  Then the exit code should be 256
66
66
  And the stdout should match "1 example, 1 failure"
67
67
  And the stdout should match "expected that 9 would be a multiple of 4"
@@ -83,7 +83,7 @@ Feature: define matcher
83
83
  it {should_not be_a_multiple_of(3)}
84
84
  end
85
85
  """
86
- When I run "spec matcher_with_failure_for_message_spec.rb"
86
+ When I run "rspec matcher_with_failure_for_message_spec.rb"
87
87
  Then the exit code should be 256
88
88
  And the stdout should match "1 example, 1 failure"
89
89
  And the stdout should match "expected that 9 would not be a multiple of 3"
@@ -108,7 +108,7 @@ Feature: define matcher
108
108
  it {should_not be_a_multiple_of(4)}
109
109
  end
110
110
  """
111
- When I run "spec matcher_overriding_description_spec.rb --format specdoc"
111
+ When I run "rspec matcher_overriding_description_spec.rb --format specdoc"
112
112
  Then the exit code should be 0
113
113
  And the stdout should match "2 examples, 0 failures"
114
114
  And the stdout should match "should be multiple of 3"
@@ -131,7 +131,7 @@ Feature: define matcher
131
131
  it {should have_7_fingers}
132
132
  end
133
133
  """
134
- When I run "spec matcher_with_no_args_spec.rb --format specdoc"
134
+ When I run "rspec matcher_with_no_args_spec.rb --format specdoc"
135
135
  Then the exit code should be 0
136
136
  And the stdout should match "1 example, 0 failures"
137
137
  And the stdout should match "should have 7 fingers"
@@ -149,7 +149,7 @@ Feature: define matcher
149
149
  it {should be_the_sum_of(1,2,3,4)}
150
150
  end
151
151
  """
152
- When I run "spec matcher_with_multiple_args_spec.rb --format specdoc"
152
+ When I run "rspec matcher_with_multiple_args_spec.rb --format specdoc"
153
153
  Then the exit code should be 0
154
154
  And the stdout should match "1 example, 0 failures"
155
155
  And the stdout should match "should be the sum of 1, 2, 3, and 4"
@@ -173,7 +173,7 @@ Feature: define matcher
173
173
  end
174
174
  end
175
175
  """
176
- When I run "spec matcher_with_internal_helper_spec.rb"
176
+ When I run "rspec matcher_with_internal_helper_spec.rb"
177
177
  Then the exit code should be 0
178
178
  And the stdout should match "1 example, 0 failures"
179
179
 
@@ -18,6 +18,6 @@ Feature: mock with rspec
18
18
  end
19
19
  end
20
20
  """
21
- When I run "spec rspec_example_spec.rb"
21
+ When I run "rspec rspec_example_spec.rb"
22
22
  Then the stdout should match "1 example, 0 failures"
23
23
  And the exit code should be 0
@@ -0,0 +1,68 @@
1
+ Feature: block local expectations
2
+
3
+ In order to set message expectations on ...
4
+ As an RSpec user
5
+ I want to configure the evaluation context
6
+
7
+ Background:
8
+ Given a file named "account.rb" with:
9
+ """
10
+ class Account
11
+ def self.create
12
+ yield new
13
+ end
14
+
15
+ def opening_balance(amount, currency)
16
+ end
17
+ end
18
+ """
19
+
20
+ Scenario: passing example
21
+ Given a file named "account_passing_spec.rb" with:
22
+ """
23
+ require 'account'
24
+
25
+ Rspec::Core.configure do |config|
26
+ config.mock_framework = :rspec
27
+ end
28
+
29
+ describe "account DSL" do
30
+ it "it succeeds when the block local receives the given call" do
31
+ account = Account.new
32
+ Account.should_receive(:create).and_yield do |account|
33
+ account.should_receive(:opening_balance).with(100, :USD)
34
+ end
35
+ Account.create do
36
+ opening_balance 100, :USD
37
+ end
38
+ end
39
+ end
40
+ """
41
+ When I run "rspec account_passing_spec.rb"
42
+ Then the stdout should match "1 example, 0 failures"
43
+
44
+ Scenario: failing example
45
+
46
+ Given a file named "account_failing_spec.rb" with:
47
+ """
48
+ require 'account'
49
+
50
+ Rspec::Core.configure do |config|
51
+ config.mock_framework = :rspec
52
+ end
53
+
54
+ describe "account DSL" do
55
+ it "fails when the block local does not receive the expected call" do
56
+ account = Account.new
57
+ Account.should_receive(:create).and_yield do |account|
58
+ account.should_receive(:opening_balance).with(100, :USD)
59
+ end
60
+ Account.create do
61
+ # opening_balance is not called here
62
+ end
63
+ end
64
+ end
65
+ """
66
+
67
+ When I run "rspec account_failing_spec.rb"
68
+ Then the stdout should match "1 example, 1 failure"
@@ -6,6 +6,10 @@ Feature: Spec and test together
6
6
  Scenario: stub in before
7
7
  Given a file named "stub_and_mocks_spec.rb" with:
8
8
  """
9
+ Rspec::Core.configure do |config|
10
+ config.mock_framework = :rspec
11
+ end
12
+
9
13
  describe "a stub in before" do
10
14
  before(:each) do
11
15
  @messenger = mock('messenger').as_null_object
@@ -18,5 +22,5 @@ Feature: Spec and test together
18
22
  end
19
23
  end
20
24
  """
21
- When I run "spec stub_and_mocks_spec.rb --format nested"
25
+ When I run "rspec stub_and_mocks_spec.rb -fs"
22
26
  Then the stdout should match "expected :foo with (\"first\") but received it with ([\"second\"], [\"third\"])"