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
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  def describe_double(describes=Object)
4
4
  group = Rspec::Core::ExampleGroup.describe(describes) {}
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Example, :parent_metadata => 'sample' do
4
4
 
@@ -6,62 +6,52 @@ describe Rspec::Core::Example, :parent_metadata => 'sample' do
6
6
  behaviour = stub('behaviour', :metadata => { :behaviour => { :name => 'behaviour_name' }})
7
7
  @example = Rspec::Core::Example.new(behaviour, 'description', {}, (lambda {}))
8
8
  end
9
-
9
+
10
10
  describe "attr readers" do
11
-
12
11
  it "should have one for the parent behaviour" do
13
12
  @example.should respond_to(:behaviour)
14
13
  end
15
-
14
+
16
15
  it "should have one for it's description" do
17
16
  @example.should respond_to(:description)
18
17
  end
19
-
18
+
20
19
  it "should have one for it's metadata" do
21
20
  @example.should respond_to(:metadata)
22
21
  end
23
-
22
+
24
23
  it "should have one for it's block" do
25
24
  @example.should respond_to(:example_block)
26
25
  end
27
-
28
26
  end
29
-
27
+
30
28
  describe '#inspect' do
31
-
32
29
  it "should return 'behaviour_name - description'" do
33
30
  @example.inspect.should == 'behaviour_name - description'
34
31
  end
35
-
36
32
  end
37
-
33
+
38
34
  describe '#to_s' do
39
-
40
35
  it "should return #inspect" do
41
36
  @example.to_s.should == @example.inspect
42
37
  end
43
-
44
38
  end
45
-
39
+
46
40
  describe "accessing metadata within a running example" do
47
-
48
41
  it "should have a reference to itself when running" do
49
42
  running_example.description.should == "should have a reference to itself when running"
50
43
  end
51
-
44
+
52
45
  it "should be able to access the behaviours top level metadata as if it were its own" do
53
46
  running_example.behaviour.metadata.should include(:parent_metadata => 'sample')
54
47
  running_example.metadata.should include(:parent_metadata => 'sample')
55
48
  end
56
-
57
49
  end
58
-
50
+
59
51
  describe "#run" do
60
-
61
52
  pending "should run after(:each) when the example fails"
62
-
53
+
63
54
  pending "should run after(:each) when the example raises an Exception"
64
-
65
55
  end
66
-
56
+
67
57
  end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Formatters::BaseFormatter do
4
4
 
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Formatters::DocumentationFormatter do
4
4
 
@@ -1,4 +1,5 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
+ require 'stringio'
2
3
 
3
4
  describe Rspec::Core::Formatters::ProgressFormatter do
4
5
 
@@ -6,8 +7,8 @@ describe Rspec::Core::Formatters::ProgressFormatter do
6
7
  @output = StringIO.new
7
8
  @formatter = Rspec::Core::Formatters::ProgressFormatter.new
8
9
  @formatter.start(2)
9
- @formatter.stubs(:color_enabled?).returns(false)
10
- @formatter.stubs(:output).returns(@output)
10
+ @formatter.stub!(:color_enabled?).and_return(false)
11
+ @formatter.stub!(:output).and_return(@output)
11
12
  end
12
13
 
13
14
  it "should produce line break on start dump" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::KernelExtensions do
4
4
 
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ module Rspec
4
+ module Core
5
+ describe Metadata do
6
+ describe "#generated_name" do
7
+ it "generates name for top level example group" do
8
+ m = Metadata.new
9
+ m.process("description", :caller => caller(0))
10
+ m[:behaviour][:name].should == "description"
11
+ end
12
+
13
+ it "concats args to describe()" do
14
+ m = Metadata.new
15
+ m.process(String, "with dots", :caller => caller(0))
16
+ m[:behaviour][:name].should == "String with dots"
17
+ end
18
+
19
+ it "concats nested names" do
20
+ m = Metadata.new(:behaviour => {:name => 'parent'})
21
+ m.process(String, "child", :caller => caller(0))
22
+ m[:behaviour][:name].should == "parent child"
23
+ end
24
+
25
+ it "strips the name" do
26
+ m = Metadata.new
27
+ m.process(" description \n", :caller => caller(0))
28
+ m[:behaviour][:name].should == "description"
29
+ end
30
+ end
31
+
32
+ describe "#determine_file_path" do
33
+ it "finds the first spec file in the caller array" do
34
+ m = Metadata.new
35
+ m.process(:caller => [
36
+ "foo",
37
+ "#{__FILE__}:#{__LINE__}",
38
+ "bar_spec.rb:23",
39
+ "baz"
40
+ ])
41
+ m[:behaviour][:file_path].should == __FILE__
42
+ end
43
+ end
44
+
45
+ describe "#determine_line_number" do
46
+ it "finds the line number with the first spec file " do
47
+ m = Metadata.new
48
+ m.process(:caller => [
49
+ "foo",
50
+ "#{__FILE__}:#{__LINE__}",
51
+ "bar_spec.rb:23",
52
+ "baz"
53
+ ])
54
+ m[:behaviour][:line_number].should == __LINE__ - 4
55
+ end
56
+ it "uses the number after the first : for ruby 1.9" do
57
+ m = Metadata.new
58
+ m.process(:caller => [
59
+ "foo",
60
+ "#{__FILE__}:#{__LINE__}:999",
61
+ "bar_spec.rb:23",
62
+ "baz"
63
+ ])
64
+ m[:behaviour][:line_number].should == __LINE__ - 4
65
+ end
66
+ end
67
+
68
+ describe "#metadata_for_example" do
69
+ let(:caller_to_use) { caller(0) }
70
+ let(:caller_line_number) { __LINE__ - 1 }
71
+ let(:metadata) { Metadata.new.process(:caller => caller_to_use) }
72
+ let(:mfe) { metadata.for_example("this description", {:caller => caller_to_use, :arbitrary => :options}) }
73
+
74
+ it "stores the description" do
75
+ mfe[:description].should == "this description"
76
+ end
77
+
78
+ it "creates an empty execution result" do
79
+ mfe[:execution_result].should == {}
80
+ end
81
+
82
+ it "stores the caller" do
83
+ mfe[:caller].should == caller_to_use
84
+ end
85
+
86
+ it "extracts file path from caller" do
87
+ mfe[:file_path].should == __FILE__
88
+ end
89
+
90
+ it "extracts line number from caller" do
91
+ mfe[:line_number].should == caller_line_number
92
+ end
93
+
94
+ it "merges arbitrary options" do
95
+ mfe[:arbitrary].should == :options
96
+ end
97
+
98
+ end
99
+ end
100
+ end
101
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Mocha Regression involving double reporting of errors" do
4
4
 
@@ -10,7 +10,7 @@ describe "Mocha Regression involving double reporting of errors" do
10
10
 
11
11
  use_formatter(formatter) do
12
12
 
13
- isolate_behaviour do
13
+ isolate_example_group do
14
14
  desc = Rspec::Core::ExampleGroup.describe("my favorite pony") do
15
15
  example("showing a double fail") do
16
16
  foo = "string"
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::Runner do
4
4
 
@@ -13,14 +13,14 @@ describe Rspec::Core::Runner do
13
13
  describe 'at_exit' do
14
14
 
15
15
  it 'should set an at_exit hook if none is already set' do
16
- Rspec::Core::Runner.stubs(:installed_at_exit?).returns(false)
17
- Rspec::Core::Runner.expects(:at_exit)
16
+ Rspec::Core::Runner.stub!(:installed_at_exit?).and_return(false)
17
+ Rspec::Core::Runner.should_receive(:at_exit)
18
18
  Rspec::Core::Runner.autorun
19
19
  end
20
20
 
21
21
  it 'should not set the at_exit hook if it is already set' do
22
- Rspec::Core::Runner.stubs(:installed_at_exit?).returns(true)
23
- Rspec::Core::Runner.expects(:at_exit).never
22
+ Rspec::Core::Runner.stub!(:installed_at_exit?).and_return(true)
23
+ Rspec::Core::Runner.should_receive(:at_exit).never
24
24
  Rspec::Core::Runner.autorun
25
25
  end
26
26
 
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core::SharedBehaviour do
4
4
 
@@ -25,7 +25,7 @@ describe Rspec::Core::SharedBehaviour do
25
25
  describe "share_examples_for" do
26
26
 
27
27
  it "should capture the given name and block in the Worlds collection of shared behaviours" do
28
- Rspec::Core.world.shared_behaviours.expects(:[]=).with(:foo, anything)
28
+ Rspec::Core.world.shared_behaviours.should_receive(:[]=).with(:foo, anything)
29
29
  share_examples_for(:foo) { }
30
30
  end
31
31
 
@@ -47,8 +47,8 @@ describe Rspec::Core::SharedBehaviour do
47
47
  'extra_helper'
48
48
  end
49
49
  }
50
- Rspec::Core.world.stubs(:shared_behaviours).returns({ :a => block1, :shared_behaviour => block2 })
51
- group.expects(:module_eval).once
50
+ Rspec::Core.world.stub!(:shared_behaviours).and_return({ :a => block1, :shared_behaviour => block2 })
51
+ group.should_receive(:module_eval).once
52
52
  group.it_should_behave_like :shared_behaviour
53
53
  end
54
54
 
@@ -58,7 +58,7 @@ describe Rspec::Core::SharedBehaviour do
58
58
  def self.class_helper; end
59
59
  def extra_helper; end
60
60
  }
61
- Rspec::Core.world.stubs(:shared_behaviours).returns({ :shared_behaviour => block })
61
+ Rspec::Core.world.stub!(:shared_behaviours).and_return({ :shared_behaviour => block })
62
62
  group.it_should_behave_like :shared_behaviour
63
63
  with_ruby(1.8) do
64
64
  group.instance_methods.should include('extra_helper')
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  class Bar; end
4
4
  class Foo; end
@@ -7,7 +7,7 @@ describe Rspec::Core::World do
7
7
 
8
8
  before do
9
9
  @world = Rspec::Core::World.new
10
- Rspec::Core.stubs(:world).returns(@world)
10
+ Rspec::Core.stub!(:world).and_return(@world)
11
11
  end
12
12
 
13
13
  describe "behaviour groups" do
@@ -100,7 +100,7 @@ describe Rspec::Core::World do
100
100
  it "should find nothing if all describes match the exclusion filter" do
101
101
  options = { :network_access => true }
102
102
 
103
- isolate_behaviour do
103
+ isolate_example_group do
104
104
  group1 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", options) do
105
105
  it("foo") {}
106
106
  it("bar") {}
@@ -109,7 +109,7 @@ describe Rspec::Core::World do
109
109
  @world.apply_exclusion_filters(group1.examples, :network_access => true).should == []
110
110
  end
111
111
 
112
- isolate_behaviour do
112
+ isolate_example_group do
113
113
  group2 = Rspec::Core::ExampleGroup.describe(Bar, "find group-1") do
114
114
  it("foo", :network_access => true) {}
115
115
  it("bar") {}
@@ -121,7 +121,7 @@ describe Rspec::Core::World do
121
121
  end
122
122
 
123
123
  it "should find nothing if a regexp matches the exclusion filter" do
124
- isolate_behaviour do
124
+ isolate_example_group do
125
125
  group = Rspec::Core::ExampleGroup.describe(Bar, "find group-1", :name => "exclude me with a regex", :another => "foo") do
126
126
  it("foo") {}
127
127
  it("bar") {}
@@ -154,9 +154,9 @@ describe Rspec::Core::World do
154
154
  end
155
155
 
156
156
  it "should run matches" do
157
- Rspec::Core.world.stubs(:exclusion_filter).returns({ :awesome => false })
158
- Rspec::Core.world.stubs(:filter).returns({ :color => :red })
159
- Rspec::Core.world.stubs(:behaviours).returns([@group1])
157
+ Rspec::Core.world.stub!(:exclusion_filter).and_return({ :awesome => false })
158
+ Rspec::Core.world.stub!(:filter).and_return({ :color => :red })
159
+ Rspec::Core.world.stub!(:behaviours).and_return([@group1])
160
160
  filtered_behaviours = @world.filter_behaviours
161
161
  filtered_behaviours.should == [@group1]
162
162
  @group1.examples_to_run.should == @group1.examples[0..1]
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Rspec::Core do
4
4
 
@@ -3,11 +3,11 @@ lib_path = File.expand_path("#{dir}/../lib")
3
3
  $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
4
4
 
5
5
  require 'rubygems'
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../expectations/lib'))
6
+ $LOAD_PATH.unshift(File.expand_path('../../../expectations/lib'), __FILE__)
7
7
  require 'rspec/expectations'
8
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../mocks/lib'))
8
+ $LOAD_PATH.unshift(File.expand_path('../../../mocks/lib'), __FILE__)
9
9
  require 'rspec/mocks'
10
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.expand_path('../../lib'), __FILE__)
11
11
  require 'rspec/core'
12
12
 
13
13
  Rspec::Core::ExampleGroup.send(:include, Rspec::Matchers)
@@ -17,7 +17,6 @@ def with_ruby(version)
17
17
  end
18
18
 
19
19
  require 'rubygems'
20
- require 'mocha'
21
20
 
22
21
  require File.expand_path(File.dirname(__FILE__) + "/resources/example_classes")
23
22
 
@@ -39,10 +38,16 @@ def remove_last_describe_from_world
39
38
  Rspec::Core.world.behaviours.pop
40
39
  end
41
40
 
42
- def isolate_behaviour
41
+ def isolate_example_group
43
42
  if block_given?
44
- yield
45
- Rspec::Core.world.behaviours.pop
43
+ example_groups = Rspec::Core.world.behaviours.dup
44
+ begin
45
+ Rspec::Core.world.behaviours.clear
46
+ yield
47
+ ensure
48
+ Rspec::Core.world.behaviours.clear
49
+ Rspec::Core.world.behaviours.concat(example_groups)
50
+ end
46
51
  end
47
52
  end
48
53
 
@@ -66,7 +71,9 @@ def not_in_editor?
66
71
  end
67
72
 
68
73
  Rspec::Core.configure do |c|
69
- c.mock_framework = :mocha
74
+ c.mock_framework = :rspec
75
+ # c.filter_run :focused => true
76
+ # TODO: Filter run needs normal before/after/include filter logic
70
77
  c.filter_run :focused => true
71
78
  c.color_enabled = not_in_editor?
72
79
  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;bin/rspec -cfn #{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