rspec-core 2.0.0.a1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/.treasure_map.rb +23 -0
  4. data/License.txt +22 -0
  5. data/README.markdown +9 -0
  6. data/Rakefile +76 -0
  7. data/TODO.markdown +16 -0
  8. data/VERSION +1 -0
  9. data/VERSION.yml +5 -0
  10. data/bin/rspec +12 -0
  11. data/cucumber.yml +2 -0
  12. data/example_specs/failing/README.txt +7 -0
  13. data/example_specs/failing/diffing_spec.rb +36 -0
  14. data/example_specs/failing/failing_implicit_docstrings_example.rb +19 -0
  15. data/example_specs/failing/failure_in_after.rb +10 -0
  16. data/example_specs/failing/failure_in_before.rb +10 -0
  17. data/example_specs/failing/mocking_example.rb +40 -0
  18. data/example_specs/failing/mocking_with_flexmock.rb +26 -0
  19. data/example_specs/failing/mocking_with_mocha.rb +25 -0
  20. data/example_specs/failing/mocking_with_rr.rb +27 -0
  21. data/example_specs/failing/partial_mock_example.rb +20 -0
  22. data/example_specs/failing/pending_example.rb +9 -0
  23. data/example_specs/failing/predicate_example.rb +34 -0
  24. data/example_specs/failing/raising_example.rb +47 -0
  25. data/example_specs/failing/spec_helper.rb +3 -0
  26. data/example_specs/failing/syntax_error_example.rb +7 -0
  27. data/example_specs/failing/team_spec.rb +44 -0
  28. data/example_specs/failing/timeout_behaviour.rb +7 -0
  29. data/example_specs/passing/custom_formatter.rb +12 -0
  30. data/example_specs/passing/custom_matchers.rb +54 -0
  31. data/example_specs/passing/dynamic_spec.rb +9 -0
  32. data/example_specs/passing/file_accessor.rb +19 -0
  33. data/example_specs/passing/file_accessor_spec.rb +38 -0
  34. data/example_specs/passing/filtered_formatter.rb +18 -0
  35. data/example_specs/passing/filtered_formatter_example.rb +31 -0
  36. data/example_specs/passing/greeter_spec.rb +31 -0
  37. data/example_specs/passing/helper_method_example.rb +14 -0
  38. data/example_specs/passing/implicit_docstrings_example.rb +18 -0
  39. data/example_specs/passing/io_processor.rb +8 -0
  40. data/example_specs/passing/io_processor_spec.rb +21 -0
  41. data/example_specs/passing/mocking_example.rb +27 -0
  42. data/example_specs/passing/multi_threaded_example_group_runner.rb +26 -0
  43. data/example_specs/passing/nested_classes_example.rb +36 -0
  44. data/example_specs/passing/options_example.rb +31 -0
  45. data/example_specs/passing/options_formatter.rb +20 -0
  46. data/example_specs/passing/partial_mock_example.rb +29 -0
  47. data/example_specs/passing/pending_example.rb +20 -0
  48. data/example_specs/passing/predicate_example.rb +27 -0
  49. data/example_specs/passing/shared_example_group_example.rb +81 -0
  50. data/example_specs/passing/shared_stack_examples.rb +36 -0
  51. data/example_specs/passing/simple_matcher_example.rb +31 -0
  52. data/example_specs/passing/spec_helper.rb +14 -0
  53. data/example_specs/passing/stack.rb +36 -0
  54. data/example_specs/passing/stack_spec.rb +64 -0
  55. data/example_specs/passing/stack_spec_with_nested_example_groups.rb +67 -0
  56. data/example_specs/passing/stubbing_example.rb +69 -0
  57. data/example_specs/passing/yielding_example.rb +33 -0
  58. data/example_specs/ruby1.9.compatibility/access_to_constants_spec.rb +85 -0
  59. data/features-pending/command_line/line_number_option.feature +56 -0
  60. data/features-pending/command_line/line_number_option_with_example_with_no_name.feature +22 -0
  61. data/features-pending/example_groups/example_group_with_should_methods.feature +29 -0
  62. data/features-pending/example_groups/implicit_docstrings.feature +59 -0
  63. data/features-pending/example_groups/nested_groups.feature +32 -0
  64. data/features-pending/expectations/expect_change.feature +65 -0
  65. data/features-pending/expectations/expect_error.feature +44 -0
  66. data/features-pending/extensions/custom_example_group.feature +19 -0
  67. data/features-pending/formatters/custom_formatter.feature +30 -0
  68. data/features-pending/heckle/heckle.feature +56 -0
  69. data/features-pending/interop/examples_and_tests_together.feature +80 -0
  70. data/features-pending/interop/rspec_output.feature +25 -0
  71. data/features-pending/interop/test_but_not_test_unit.feature +26 -0
  72. data/features-pending/interop/test_case_with_should_methods.feature +46 -0
  73. data/features-pending/matchers/define_diffable_matcher.feature +26 -0
  74. data/features-pending/matchers/define_matcher.feature +179 -0
  75. data/features-pending/matchers/define_matcher_with_fluent_interface.feature +27 -0
  76. data/features-pending/mocks/mix_stubs_and_mocks.feature +22 -0
  77. data/features-pending/mocks/stub_implementation.feature +26 -0
  78. data/features-pending/pending/pending_examples.feature +81 -0
  79. data/features-pending/runner/specify_line_number.feature +32 -0
  80. data/features/before_and_after_blocks/before_and_after_blocks.feature +169 -0
  81. data/features/expectations/customized_message.feature +54 -0
  82. data/features/matchers/define_matcher_outside_rspec.feature +39 -0
  83. data/features/mock_framework_integration/use_flexmock.feature +23 -0
  84. data/features/mock_framework_integration/use_mocha.feature +23 -0
  85. data/features/mock_framework_integration/use_rr.feature +23 -0
  86. data/features/mock_framework_integration/use_rspec.feature +23 -0
  87. data/features/step_definitions/running_rspec_steps.rb +35 -0
  88. data/features/subject/explicit_subject.feature +31 -0
  89. data/features/subject/implicit_subject.feature +31 -0
  90. data/features/support/env.rb +82 -0
  91. data/features/support/matchers/smart_match.rb +14 -0
  92. data/lib/rspec/autorun.rb +2 -0
  93. data/lib/rspec/core.rb +38 -0
  94. data/lib/rspec/core/backward_compatibility.rb +9 -0
  95. data/lib/rspec/core/command_line_options.rb +60 -0
  96. data/lib/rspec/core/configuration.rb +222 -0
  97. data/lib/rspec/core/deprecation.rb +47 -0
  98. data/lib/rspec/core/example.rb +113 -0
  99. data/lib/rspec/core/example_group.rb +239 -0
  100. data/lib/rspec/core/example_group_subject.rb +77 -0
  101. data/lib/rspec/core/formatters.rb +16 -0
  102. data/lib/rspec/core/formatters/base_formatter.rb +123 -0
  103. data/lib/rspec/core/formatters/base_text_formatter.rb +139 -0
  104. data/lib/rspec/core/formatters/documentation_formatter.rb +84 -0
  105. data/lib/rspec/core/formatters/progress_formatter.rb +36 -0
  106. data/lib/rspec/core/kernel_extensions.rb +15 -0
  107. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +13 -0
  108. data/lib/rspec/core/mocking/with_flexmock.rb +25 -0
  109. data/lib/rspec/core/mocking/with_mocha.rb +22 -0
  110. data/lib/rspec/core/mocking/with_rr.rb +26 -0
  111. data/lib/rspec/core/mocking/with_rspec.rb +21 -0
  112. data/lib/rspec/core/rake_task.rb +88 -0
  113. data/lib/rspec/core/runner.rb +66 -0
  114. data/lib/rspec/core/shared_behaviour.rb +41 -0
  115. data/lib/rspec/core/shared_behaviour_kernel_extensions.rb +31 -0
  116. data/lib/rspec/core/version.rb +16 -0
  117. data/lib/rspec/core/world.rb +105 -0
  118. data/rspec-core.gemspec +204 -0
  119. data/script/console +8 -0
  120. data/spec/resources/example_classes.rb +67 -0
  121. data/spec/rspec/core/command_line_options_spec.rb +63 -0
  122. data/spec/rspec/core/configuration_spec.rb +171 -0
  123. data/spec/rspec/core/example_group_spec.rb +351 -0
  124. data/spec/rspec/core/example_group_subject_spec.rb +67 -0
  125. data/spec/rspec/core/example_spec.rb +67 -0
  126. data/spec/rspec/core/formatters/base_formatter_spec.rb +105 -0
  127. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +5 -0
  128. data/spec/rspec/core/formatters/progress_formatter_spec.rb +29 -0
  129. data/spec/rspec/core/kernel_extensions_spec.rb +13 -0
  130. data/spec/rspec/core/mocha_spec.rb +29 -0
  131. data/spec/rspec/core/resources/a_bar.rb +0 -0
  132. data/spec/rspec/core/resources/a_foo.rb +0 -0
  133. data/spec/rspec/core/resources/a_spec.rb +1 -0
  134. data/spec/rspec/core/resources/custom_example_group_runner.rb +14 -0
  135. data/spec/rspec/core/resources/example_classes.rb +67 -0
  136. data/spec/rspec/core/resources/utf8_encoded.rb +8 -0
  137. data/spec/rspec/core/runner_spec.rb +34 -0
  138. data/spec/rspec/core/shared_behaviour_spec.rb +185 -0
  139. data/spec/rspec/core/world_spec.rb +167 -0
  140. data/spec/rspec/core_spec.rb +35 -0
  141. data/spec/ruby_forker.rb +13 -0
  142. data/spec/spec_helper.rb +72 -0
  143. metadata +219 -0
@@ -0,0 +1,47 @@
1
+ describe "This example" do
2
+
3
+ it "should show that a NoMethodError is raised but an Exception was expected" do
4
+ proc { ''.nonexistent_method }.should raise_error
5
+ end
6
+
7
+ it "should pass" do
8
+ proc { ''.nonexistent_method }.should raise_error(NoMethodError)
9
+ end
10
+
11
+ it "should show that a NoMethodError is raised but a SyntaxError was expected" do
12
+ proc { ''.nonexistent_method }.should raise_error(SyntaxError)
13
+ end
14
+
15
+ it "should show that nothing is raised when SyntaxError was expected" do
16
+ proc { }.should raise_error(SyntaxError)
17
+ end
18
+
19
+ it "should show that a NoMethodError is raised but a Exception was expected" do
20
+ proc { ''.nonexistent_method }.should_not raise_error
21
+ end
22
+
23
+ it "should show that a NoMethodError is raised" do
24
+ proc { ''.nonexistent_method }.should_not raise_error(NoMethodError)
25
+ end
26
+
27
+ it "should also pass" do
28
+ proc { ''.nonexistent_method }.should_not raise_error(SyntaxError)
29
+ end
30
+
31
+ it "should show that a NoMethodError is raised when nothing expected" do
32
+ proc { ''.nonexistent_method }.should_not raise_error(Exception)
33
+ end
34
+
35
+ it "should show that the wrong message was received" do
36
+ proc { raise StandardError.new("what is an enterprise?") }.should raise_error(StandardError, "not this")
37
+ end
38
+
39
+ it "should show that the unexpected error/message was thrown" do
40
+ proc { raise StandardError.new("abc") }.should_not raise_error(StandardError, "abc")
41
+ end
42
+
43
+ it "should pass too" do
44
+ proc { raise StandardError.new("abc") }.should_not raise_error(StandardError, "xyz")
45
+ end
46
+
47
+ end
@@ -0,0 +1,3 @@
1
+ lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
2
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
3
+ require 'spec/autorun'
@@ -0,0 +1,7 @@
1
+ describe "when passing a block to a matcher" do
2
+ it "you should use {} instead of do/end" do
3
+ Object.new.should satisfy do
4
+ "this block is being passed to #should instead of #satisfy - use {} instead"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ class Team
5
+ attr_reader :players
6
+ def initialize
7
+ @players = Players.new
8
+ end
9
+ end
10
+
11
+ class Players
12
+ def initialize
13
+ @players = []
14
+ end
15
+ def size
16
+ @players.size
17
+ end
18
+ def include? player
19
+ raise "player must be a string" unless player.is_a?(String)
20
+ @players.include? player
21
+ end
22
+ end
23
+
24
+ describe "A new team" do
25
+
26
+ before(:each) do
27
+ @team = Team.new
28
+ end
29
+
30
+ it "should have 3 players (failing example)" do
31
+ @team.should have(3).players
32
+ end
33
+
34
+ it "should include some player (failing example)" do
35
+ @team.players.should include("Some Player")
36
+ end
37
+
38
+ it "should include 5 (failing example)" do
39
+ @team.players.should include(5)
40
+ end
41
+
42
+ it "should have no players"
43
+
44
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Something really slow" do
4
+ it "should be failed by RSpec when it takes longer than --timeout" do
5
+ sleep(2)
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'spec/runner/formatter/progress_bar_formatter'
3
+
4
+ # Example of a formatter with custom bactrace printing. Run me with:
5
+ # ruby bin/spec examples/failing -r examples/passing/custom_formatter.rb -f CustomFormatter
6
+ class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
7
+ def backtrace_line(line)
8
+ line.gsub(/([^:]*\.rb):(\d*)/) do
9
+ "<a href=\"file://#{File.expand_path($1)}\">#{$1}:#{$2}</a> "
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ module AnimalSpecHelper
2
+ class Eat
3
+ def initialize(food)
4
+ @food = food
5
+ end
6
+
7
+ def matches?(animal)
8
+ @animal = animal
9
+ @animal.eats?(@food)
10
+ end
11
+
12
+ def failure_message
13
+ "expected #{@animal} to eat #{@food}, but it does not"
14
+ end
15
+
16
+ def negative_failure_message
17
+ "expected #{@animal} not to eat #{@food}, but it does"
18
+ end
19
+ end
20
+
21
+ def eat(food)
22
+ Eat.new(food)
23
+ end
24
+ end
25
+
26
+ module Animals
27
+ class Animal
28
+ def eats?(food)
29
+ return foods_i_eat.include?(food)
30
+ end
31
+ end
32
+
33
+ class Mouse < Animal
34
+ def foods_i_eat
35
+ [:cheese]
36
+ end
37
+ end
38
+
39
+ describe Mouse do
40
+ include AnimalSpecHelper
41
+ before(:each) do
42
+ @mouse = Animals::Mouse.new
43
+ end
44
+
45
+ it "should eat cheese" do
46
+ @mouse.should eat(:cheese)
47
+ end
48
+
49
+ it "should not eat cat" do
50
+ @mouse.should_not eat(:cat)
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "The square root" do
4
+ (1..10).each do |n|
5
+ it "of #{n*n} should be #{n}" do
6
+ Math.sqrt(n*n).should == n
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ class FileAccessor
3
+ def open_and_handle_with(pathname, processor)
4
+ pathname.open do |io|
5
+ processor.process(io)
6
+ end
7
+ end
8
+ end
9
+
10
+ if __FILE__ == $0
11
+ require File.dirname(__FILE__) + '/io_processor'
12
+ require 'pathname'
13
+
14
+ accessor = FileAccessor.new
15
+ io_processor = IoProcessor.new
16
+ file = Pathname.new ARGV[0]
17
+
18
+ accessor.open_and_handle_with(file, io_processor)
19
+ end
@@ -0,0 +1,38 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/file_accessor'
3
+ require 'stringio'
4
+
5
+ describe "A FileAccessor" do
6
+ # This sequence diagram illustrates what this spec specifies.
7
+ #
8
+ # +--------------+ +----------+ +-------------+
9
+ # | FileAccessor | | Pathname | | IoProcessor |
10
+ # +--------------+ +----------+ +-------------+
11
+ # | | |
12
+ # open_and_handle_with | | |
13
+ # -------------------->| | open | |
14
+ # | |--------------->| | |
15
+ # | | io | | |
16
+ # | |<...............| | |
17
+ # | | | process(io) |
18
+ # | |---------------------------------->| |
19
+ # | | | | |
20
+ # | |<..................................| |
21
+ # | | |
22
+ #
23
+ it "should open a file and pass it to the processor's process method" do
24
+ # This is the primary actor
25
+ accessor = FileAccessor.new
26
+
27
+ # These are the primary actor's neighbours, which we mock.
28
+ file = mock "Pathname"
29
+ io_processor = mock "IoProcessor"
30
+
31
+ io = StringIO.new "whatever"
32
+ file.should_receive(:open).and_yield io
33
+ io_processor.should_receive(:process).with(io)
34
+
35
+ accessor.open_and_handle_with(file, io_processor)
36
+ end
37
+
38
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "/../../lib")
2
+ require 'spec/runner/formatter/nested_text_formatter'
3
+
4
+ class FilteredFormatter < Spec::Runner::Formatter::NestedTextFormatter
5
+ def add_example_group(example_group)
6
+ if example_group.options[:show] == false
7
+ @showing = false
8
+ else
9
+ @showing = true
10
+ puts example_group.description
11
+ end
12
+ end
13
+
14
+ def example_passed(example)
15
+ puts " " << example.description if @showing unless example.options[:show] == false
16
+ end
17
+ end
18
+
@@ -0,0 +1,31 @@
1
+ # This demonstrates how you can write custom formatters to handle arbitrary
2
+ # options passed to the +describe+ and +it+ methods. To see it in action, stand
3
+ # in the project root and say:
4
+ #
5
+ # bin/spec -r examples/passing/filtered_formatter.rb examples/passing/filtered_formatter_example.rb -f FilteredFormatter
6
+ #
7
+ # You should only see the examples and groups below that are not explicitly
8
+ # marked :show => false
9
+ #
10
+ # group 1
11
+ # example 1 a
12
+ # group 3
13
+ # example 3
14
+
15
+
16
+ describe "group 1", :show => true do
17
+ it "example 1 a", :show => true do
18
+ end
19
+ it "example 1 b", :show => false do
20
+ end
21
+ end
22
+
23
+ describe "group 2", :show => false do
24
+ it "example 2" do
25
+ end
26
+ end
27
+
28
+ describe "group 3" do
29
+ it "example 3" do
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ # greeter.rb
3
+ #
4
+ # Based on http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle
5
+ #
6
+ # Run with:
7
+ #
8
+ # spec greeter_spec.rb --heckle Greeter
9
+ #
10
+ class Greeter
11
+ def initialize(person = nil)
12
+ @person = person
13
+ end
14
+
15
+ def greet
16
+ @person.nil? ? "Hi there!" : "Hi #{@person}!"
17
+ end
18
+ end
19
+
20
+ describe "Greeter" do
21
+ it "should say Hi to person" do
22
+ greeter = Greeter.new("Kevin")
23
+ greeter.greet.should == "Hi Kevin!"
24
+ end
25
+
26
+ it "should say Hi to nobody" do
27
+ greeter = Greeter.new
28
+ # Uncomment the next line to make Heckle happy
29
+ #greeter.greet.should == "Hi there!"
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module HelperMethodExample
4
+ describe "an example group with helper a method" do
5
+ def helper_method
6
+ "received call"
7
+ end
8
+
9
+ it "should make that method available to specs" do
10
+ helper_method.should == "received call"
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ # Run "spec implicit_docstrings_example.rb --format specdoc" to see the output of this file
4
+
5
+ describe "Examples with no docstrings generate their own:" do
6
+
7
+ specify { 3.should be < 5 }
8
+
9
+ specify { ["a"].should include("a") }
10
+
11
+ specify { [1,2,3].should respond_to(:size) }
12
+
13
+ end
14
+
15
+ describe 1 do
16
+ it { should == 1 }
17
+ it { should be < 2}
18
+ end
@@ -0,0 +1,8 @@
1
+ class DataTooShort < StandardError; end
2
+
3
+ class IoProcessor
4
+ # Does some fancy stuff unless the length of +io+ is shorter than 32
5
+ def process(io)
6
+ raise DataTooShort if io.read.length < 32
7
+ end
8
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/io_processor'
3
+ require 'stringio'
4
+
5
+ describe "An IoProcessor" do
6
+ before(:each) do
7
+ @processor = IoProcessor.new
8
+ end
9
+
10
+ it "should raise nothing when the file is exactly 32 bytes" do
11
+ lambda {
12
+ @processor.process(StringIO.new("z"*32))
13
+ }.should_not raise_error
14
+ end
15
+
16
+ it "should raise an exception when the file length is less than 32 bytes" do
17
+ lambda {
18
+ @processor.process(StringIO.new("z"*31))
19
+ }.should raise_error(DataTooShort)
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "A consumer of a mock" do
4
+ it "should be able to send messages to the mock" do
5
+ mock = mock("poke me")
6
+ mock.should_receive(:poke)
7
+ mock.poke
8
+ end
9
+ end
10
+
11
+ describe "a mock" do
12
+ it "should be able to mock the same message twice w/ different args" do
13
+ mock = mock("mock")
14
+ mock.should_receive(:msg).with(:arg1).and_return(:val1)
15
+ mock.should_receive(:msg).with(:arg2).and_return(:val2)
16
+ mock.msg(:arg1).should eql(:val1)
17
+ mock.msg(:arg2).should eql(:val2)
18
+ end
19
+
20
+ it "should be able to mock the same message twice w/ different args in reverse order" do
21
+ mock = mock("mock")
22
+ mock.should_receive(:msg).with(:arg1).and_return(:val1)
23
+ mock.should_receive(:msg).with(:arg2).and_return(:val2)
24
+ mock.msg(:arg2).should eql(:val2)
25
+ mock.msg(:arg1).should eql(:val1)
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ class MultiThreadedExampleGroupRunner < Spec::Runner::ExampleGroupRunner
2
+ def initialize(options, arg)
3
+ super(options)
4
+ # configure these
5
+ @thread_count = 4
6
+ @thread_wait = 0
7
+ end
8
+
9
+ def run
10
+ @threads = []
11
+ q = Queue.new
12
+ example_groups.each { |b| q << b}
13
+ success = true
14
+ @thread_count.times do
15
+ @threads << Thread.new(q) do |queue|
16
+ while not queue.empty?
17
+ example_group = queue.pop
18
+ success &= example_group.suite.run(nil)
19
+ end
20
+ end
21
+ sleep @thread_wait
22
+ end
23
+ @threads.each {|t| t.join}
24
+ success
25
+ end
26
+ end