dchelimsky-rspec 1.1.11 → 1.1.11.1

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.
Files changed (103) hide show
  1. data/.autotest +4 -0
  2. data/History.txt +19 -3
  3. data/Manifest.txt +6 -1
  4. data/examples/failing/README.txt +7 -0
  5. data/examples/failing/diffing_spec.rb +36 -0
  6. data/examples/failing/failing_autogenerated_docstrings_example.rb +19 -0
  7. data/examples/failing/failure_in_setup.rb +10 -0
  8. data/examples/failing/failure_in_teardown.rb +10 -0
  9. data/examples/failing/mocking_example.rb +40 -0
  10. data/examples/failing/mocking_with_flexmock.rb +26 -0
  11. data/examples/failing/mocking_with_mocha.rb +25 -0
  12. data/examples/failing/mocking_with_rr.rb +27 -0
  13. data/examples/failing/partial_mock_example.rb +20 -0
  14. data/examples/failing/predicate_example.rb +34 -0
  15. data/examples/failing/raising_example.rb +47 -0
  16. data/examples/failing/spec_helper.rb +3 -0
  17. data/examples/failing/syntax_error_example.rb +7 -0
  18. data/examples/failing/team_spec.rb +44 -0
  19. data/examples/failing/timeout_behaviour.rb +7 -0
  20. data/examples/passing/custom_formatter.rb +1 -1
  21. data/examples/passing/simple_matcher_example.rb +31 -0
  22. data/lib/autotest/rspec.rb +1 -1
  23. data/lib/spec/dsl/main.rb +82 -0
  24. data/lib/spec/dsl.rb +1 -0
  25. data/lib/spec/example/before_and_after_hooks.rb +2 -1
  26. data/lib/spec/example/configuration.rb +1 -1
  27. data/lib/spec/example/example_group.rb +1 -0
  28. data/lib/spec/example/example_group_factory.rb +2 -1
  29. data/lib/spec/example/example_group_methods.rb +40 -25
  30. data/lib/spec/example/example_methods.rb +19 -8
  31. data/lib/spec/example.rb +15 -17
  32. data/lib/spec/expectations/handler.rb +23 -28
  33. data/lib/spec/expectations/wrap_expectation.rb +56 -0
  34. data/lib/spec/expectations.rb +22 -18
  35. data/lib/spec/extensions.rb +0 -1
  36. data/lib/spec/interop/test/unit/testcase.rb +19 -17
  37. data/lib/spec/matchers/be_close.rb +6 -22
  38. data/lib/spec/matchers/eql.rb +7 -25
  39. data/lib/spec/matchers/equal.rb +6 -24
  40. data/lib/spec/matchers/errors.rb +5 -0
  41. data/lib/spec/matchers/exist.rb +8 -14
  42. data/lib/spec/matchers/generated_descriptions.rb +48 -0
  43. data/lib/spec/matchers/has.rb +12 -28
  44. data/lib/spec/matchers/include.rb +12 -9
  45. data/lib/spec/matchers/match.rb +8 -27
  46. data/lib/spec/matchers/method_missing.rb +9 -0
  47. data/lib/spec/matchers/operator_matcher.rb +23 -46
  48. data/lib/spec/matchers/raise_error.rb +4 -8
  49. data/lib/spec/matchers/respond_to.rb +2 -1
  50. data/lib/spec/matchers/throw_symbol.rb +9 -3
  51. data/lib/spec/mocks/message_expectation.rb +0 -5
  52. data/lib/spec/mocks/proxy.rb +12 -10
  53. data/lib/spec/rake/spectask.rb +4 -6
  54. data/lib/spec/runner/class_and_arguments_parser.rb +7 -9
  55. data/lib/spec/runner/command_line.rb +6 -8
  56. data/lib/spec/runner/formatter/base_text_formatter.rb +3 -2
  57. data/lib/spec/runner/option_parser.rb +4 -6
  58. data/lib/spec/runner/spec_parser.rb +5 -5
  59. data/lib/spec/runner.rb +37 -39
  60. data/lib/spec/story/runner/story_runner.rb +10 -6
  61. data/lib/spec/story/runner.rb +40 -42
  62. data/lib/spec/story/world.rb +66 -70
  63. data/lib/spec/version.rb +3 -1
  64. data/lib/spec.rb +21 -19
  65. data/rspec.gemspec +15 -6
  66. data/spec/autotest/autotest_helper.rb +2 -2
  67. data/spec/autotest/discover_spec.rb +4 -15
  68. data/spec/autotest/failed_results_re_spec.rb +24 -0
  69. data/spec/autotest/rspec_spec.rb +0 -37
  70. data/spec/spec/dsl/main_spec.rb +65 -0
  71. data/spec/spec/example/example_group_class_definition_spec.rb +6 -2
  72. data/spec/spec/example/example_group_factory_spec.rb +2 -1
  73. data/spec/spec/example/example_group_methods_spec.rb +138 -141
  74. data/spec/spec/example/example_group_spec.rb +3 -5
  75. data/spec/spec/example/example_methods_spec.rb +60 -23
  76. data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
  77. data/spec/spec/interop/test/unit/spec_spec.rb +1 -5
  78. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +4 -0
  79. data/spec/spec/matchers/be_close_spec.rb +12 -10
  80. data/spec/spec/matchers/description_generation_spec.rb +1 -1
  81. data/spec/spec/matchers/eql_spec.rb +7 -6
  82. data/spec/spec/matchers/equal_spec.rb +7 -6
  83. data/spec/spec/matchers/has_spec.rb +1 -1
  84. data/spec/spec/matchers/have_spec.rb +23 -18
  85. data/spec/spec/matchers/include_spec.rb +24 -0
  86. data/spec/spec/matchers/matcher_methods_spec.rb +1 -13
  87. data/spec/spec/matchers/throw_symbol_spec.rb +3 -3
  88. data/spec/spec/mocks/bug_report_11545_spec.rb +4 -5
  89. data/spec/spec/mocks/bug_report_496.rb +11 -9
  90. data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
  91. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +1 -1
  92. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +4 -14
  93. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +1 -1
  94. data/spec/spec/runner/options_spec.rb +1 -1
  95. data/spec/spec/runner/spec_parser_spec.rb +76 -80
  96. data/spec/spec_helper.rb +4 -0
  97. data/stories/example_groups/autogenerated_docstrings +4 -4
  98. data/stories/interop/test_but_not_test_unit +14 -0
  99. data/stories/resources/helpers/story_helper.rb +1 -1
  100. data/stories/resources/test/spec_including_test_but_not_unit.rb +11 -0
  101. data/story_server/prototype/javascripts/prototype.js +1 -1
  102. metadata +34 -53
  103. data/lib/spec/extensions/metaclass.rb +0 -7
data/.autotest ADDED
@@ -0,0 +1,4 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.add_exception("spec/interop/test/unit/resources")
3
+ at.add_exception("spec/spec/runner/drb_command_line_spec.rb")
4
+ end
data/History.txt CHANGED
@@ -1,14 +1,30 @@
1
1
  === Maintenance
2
2
 
3
- * 2 major enhancements
3
+ * 2 deprecations
4
+
5
+ * deprecated ExampleMethods#implementation_backtrace - use ExampleMethods#backtrace instead
6
+ * deprecated ExampleGroupMethods#example_group_backtrace - use ExampleGroupMethods#backtrace instead
4
7
 
5
- * it { should matcher } - syntax support from Joe Ferris
8
+ * 3 major enhancements
9
+
10
+ * it { should matcher } - support for implicit receiver of #should (Joe Ferris of thoughtbot)
11
+ * subject { ... } - works in conjunction with implicit receiver of #should
6
12
  * wrap_expectation (for wrapping multiple expectations and/or t/u assertions)
7
13
 
8
- * 1 minor enhancement
14
+ * 4 minor enhancements
9
15
 
10
16
  * should throw_symbol accepts an optional argument: should throw_symbol(:sym, arg)
17
+ * fixed --line for jruby (Zach Moazeni)
18
+ * assorted small changes to support Ruby 1.9 (got a way to go)
19
+ * removed all instances of class << self - I do know who I am
20
+
21
+ * 4 bug fixes
11
22
 
23
+ * fixed bug where {:a => 1, :b => 2}.should include(:a, :b) failed (Yossef Mendelssohn)
24
+ * only try to load Test::Unit if Test::Unit is defined (not just Test)
25
+ * Allow stubs on parent and child classes simultaneously (Jim Lindley). Fixes #600.
26
+ * BaseTextFormatter will now create the directory in a WHERE string (Adam Anderson). Fixes #616.
27
+
12
28
  === Version 1.1.11 / 2008-10-24
13
29
 
14
30
  * 1 major enhancement
data/Manifest.txt CHANGED
@@ -45,6 +45,7 @@ examples/passing/predicate_example.rb
45
45
  examples/passing/priority.txt
46
46
  examples/passing/shared_example_group_example.rb
47
47
  examples/passing/shared_stack_examples.rb
48
+ examples/passing/simple_matcher_example.rb
48
49
  examples/passing/spec_helper.rb
49
50
  examples/passing/stack.rb
50
51
  examples/passing/stack_spec.rb
@@ -83,7 +84,6 @@ lib/spec/expectations/handler.rb
83
84
  lib/spec/expectations/wrap_expectation.rb
84
85
  lib/spec/extensions.rb
85
86
  lib/spec/extensions/class.rb
86
- lib/spec/extensions/metaclass.rb
87
87
  lib/spec/interop/test.rb
88
88
  lib/spec/interop/test/unit/autorunner.rb
89
89
  lib/spec/interop/test/unit/testcase.rb
@@ -186,6 +186,7 @@ spec/README.jruby
186
186
  spec/autotest/autotest_helper.rb
187
187
  spec/autotest/autotest_matchers.rb
188
188
  spec/autotest/discover_spec.rb
189
+ spec/autotest/failed_results_re_spec.rb
189
190
  spec/autotest/rspec_spec.rb
190
191
  spec/rspec_suite.rb
191
192
  spec/ruby_forker.rb
@@ -250,6 +251,7 @@ spec/spec/mocks/bug_report_10263_spec.rb
250
251
  spec/spec/mocks/bug_report_11545_spec.rb
251
252
  spec/spec/mocks/bug_report_15719_spec.rb
252
253
  spec/spec/mocks/bug_report_496.rb
254
+ spec/spec/mocks/bug_report_600_spec.rb
253
255
  spec/spec/mocks/bug_report_7611_spec.rb
254
256
  spec/spec/mocks/bug_report_7805_spec.rb
255
257
  spec/spec/mocks/bug_report_8165_spec.rb
@@ -279,6 +281,7 @@ spec/spec/runner/empty_file.txt
279
281
  spec/spec/runner/examples.txt
280
282
  spec/spec/runner/failed.txt
281
283
  spec/spec/runner/formatter/base_formatter_spec.rb
284
+ spec/spec/runner/formatter/base_text_formatter_spec.rb
282
285
  spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb
283
286
  spec/spec/runner/formatter/failing_examples_formatter_spec.rb
284
287
  spec/spec/runner/formatter/html_formatted-1.8.4.html
@@ -348,6 +351,7 @@ stories/example_groups/stories.rb
348
351
  stories/helper.rb
349
352
  stories/interop/examples_and_tests_together
350
353
  stories/interop/stories.rb
354
+ stories/interop/test_but_not_test_unit
351
355
  stories/interop/test_case_with_should_methods
352
356
  stories/mock_framework_integration/stories.rb
353
357
  stories/mock_framework_integration/use_flexmock.story
@@ -362,6 +366,7 @@ stories/resources/spec/spec_with_flexmock.rb
362
366
  stories/resources/steps/running_rspec.rb
363
367
  stories/resources/stories/failing_story.rb
364
368
  stories/resources/test/spec_and_test_together.rb
369
+ stories/resources/test/spec_including_test_but_not_unit.rb
365
370
  stories/resources/test/test_case_with_should_methods.rb
366
371
  stories/stories/multiline_steps.story
367
372
  stories/stories/steps/multiline_steps.rb
@@ -0,0 +1,7 @@
1
+ "Why have failing examples?", you might ask.
2
+
3
+ They allow us to see failure messages. RSpec wants to provide meaningful and helpful failure messages. The failures in this directory not only provide you a way of seeing the failure messages, but they provide RSpec's own specs a way of describing what they should look like and ensuring they stay correct.
4
+
5
+ To see the types of messages you can expect, stand in this directory and run:
6
+
7
+ ../bin/spec ./*.rb
@@ -0,0 +1,36 @@
1
+ describe "Running specs with --diff" do
2
+ it "should print diff of different strings" do
3
+ uk = <<-EOF
4
+ RSpec is a
5
+ behaviour driven development
6
+ framework for Ruby
7
+ EOF
8
+ usa = <<-EOF
9
+ RSpec is a
10
+ behavior driven development
11
+ framework for Ruby
12
+ EOF
13
+ usa.should == uk
14
+ end
15
+
16
+ class Animal
17
+ def initialize(name,species)
18
+ @name,@species = name,species
19
+ end
20
+
21
+ def inspect
22
+ <<-EOA
23
+ <Animal
24
+ name=#{@name},
25
+ species=#{@species}
26
+ >
27
+ EOA
28
+ end
29
+ end
30
+
31
+ it "should print diff of different objects' pretty representation" do
32
+ expected = Animal.new "bob", "giraffe"
33
+ actual = Animal.new "bob", "tortoise"
34
+ expected.should eql(actual)
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ # Run spec w/ -fs to see the output of this file
4
+
5
+ describe "Failing examples with no descriptions" do
6
+
7
+ # description is auto-generated as "should equal(5)" based on the last #should
8
+ it do
9
+ 3.should equal(2)
10
+ 5.should equal(5)
11
+ end
12
+
13
+ it { 3.should be > 5 }
14
+
15
+ it { ["a"].should include("b") }
16
+
17
+ it { [1,2,3].should_not respond_to(:size) }
18
+
19
+ end
@@ -0,0 +1,10 @@
1
+ describe "This example" do
2
+
3
+ before(:each) do
4
+ NonExistentClass.new
5
+ end
6
+
7
+ it "should be listed as failing in setup" do
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ describe "This example" do
2
+
3
+ it "should be listed as failing in teardown" do
4
+ end
5
+
6
+ after(:each) do
7
+ NonExistentClass.new
8
+ end
9
+
10
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "Mocker" do
4
+
5
+ it "should be able to call mock()" do
6
+ mock = mock("poke me")
7
+ mock.should_receive(:poke)
8
+ mock.poke
9
+ end
10
+
11
+ it "should fail when expected message not received" do
12
+ mock = mock("poke me")
13
+ mock.should_receive(:poke)
14
+ end
15
+
16
+ it "should fail when messages are received out of order" do
17
+ mock = mock("one two three")
18
+ mock.should_receive(:one).ordered
19
+ mock.should_receive(:two).ordered
20
+ mock.should_receive(:three).ordered
21
+ mock.one
22
+ mock.three
23
+ mock.two
24
+ end
25
+
26
+ it "should get yelled at when sending unexpected messages" do
27
+ mock = mock("don't talk to me")
28
+ mock.should_not_receive(:any_message_at_all)
29
+ mock.any_message_at_all
30
+ end
31
+
32
+ it "has a bug we need to fix" do
33
+ pending "here is the bug" do
34
+ # Actually, no. It's fixed. This will fail because it passes :-)
35
+ mock = mock("Bug")
36
+ mock.should_receive(:hello)
37
+ mock.hello
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # stub frameworks like to gum up Object, so this is deliberately
2
+ # set NOT to run so that you don't accidentally run it when you
3
+ # run this dir.
4
+
5
+ # To run it, stand in this directory and say:
6
+ #
7
+ # RUN_FLEXMOCK_EXAMPLE=true ruby ../bin/spec mocking_with_flexmock.rb
8
+
9
+ if ENV['RUN_FLEXMOCK_EXAMPLE']
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :flexmock
12
+ end
13
+
14
+ describe "Flexmocks" do
15
+ it "should fail when the expected message is received with wrong arguments" do
16
+ m = flexmock("now flex!")
17
+ m.should_receive(:msg).with("arg").once
18
+ m.msg("other arg")
19
+ end
20
+
21
+ it "should fail when the expected message is not received at all" do
22
+ m = flexmock("now flex!")
23
+ m.should_receive(:msg).with("arg").once
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # stub frameworks like to gum up Object, so this is deliberately
2
+ # set NOT to run so that you don't accidentally run it when you
3
+ # run this dir.
4
+
5
+ # To run it, stand in this directory and say:
6
+ #
7
+ # RUN_MOCHA_EXAMPLE=true ruby ../bin/spec mocking_with_mocha.rb
8
+
9
+ if ENV['RUN_MOCHA_EXAMPLE']
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :mocha
12
+ end
13
+ describe "Mocha framework" do
14
+ it "should should be made available by saying config.mock_with :mocha" do
15
+ m = mock()
16
+ m.expects(:msg).with("arg")
17
+ m.msg
18
+ end
19
+ it "should should be made available by saying config.mock_with :mocha" do
20
+ o = Object.new
21
+ o.expects(:msg).with("arg")
22
+ o.msg
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # stub frameworks like to gum up Object, so this is deliberately
2
+ # set NOT to run so that you don't accidentally run it when you
3
+ # run this dir.
4
+
5
+ # To run it, stand in this directory and say:
6
+ #
7
+ # RUN_RR_EXAMPLE=true ruby ../bin/spec mocking_with_rr.rb
8
+
9
+ if ENV['RUN_RR_EXAMPLE']
10
+ Spec::Runner.configure do |config|
11
+ config.mock_with :rr
12
+ end
13
+ describe "RR framework" do
14
+ it "should should be made available by saying config.mock_with :rr" do
15
+ o = Object.new
16
+ mock(o).msg("arg")
17
+ o.msg
18
+ end
19
+ it "should should be made available by saying config.mock_with :rr" do
20
+ o = Object.new
21
+ mock(o) do |m|
22
+ m.msg("arg")
23
+ end
24
+ o.msg
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class MockableClass
4
+ def self.find id
5
+ return :original_return
6
+ end
7
+ end
8
+
9
+ describe "A partial mock" do
10
+
11
+ it "should work at the class level (but fail here due to the type mismatch)" do
12
+ MockableClass.should_receive(:find).with(1).and_return {:stub_return}
13
+ MockableClass.find("1").should equal(:stub_return)
14
+ end
15
+
16
+ it "should revert to the original after each spec" do
17
+ MockableClass.find(1).should equal(:original_return)
18
+ end
19
+
20
+ end
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class BddFramework
4
+ def intuitive?
5
+ true
6
+ end
7
+
8
+ def adopted_quickly?
9
+ #this will cause failures because it reallly SHOULD be adopted quickly
10
+ false
11
+ end
12
+ end
13
+
14
+ describe "BDD framework" do
15
+
16
+ before(:each) do
17
+ @bdd_framework = BddFramework.new
18
+ end
19
+
20
+ it "should be adopted quickly" do
21
+ #this will fail because it reallly SHOULD be adopted quickly
22
+ @bdd_framework.should be_adopted_quickly
23
+ end
24
+
25
+ it "should be intuitive" do
26
+ @bdd_framework.should be_intuitive
27
+ end
28
+
29
+ it "should not respond to test" do
30
+ #this will fail
31
+ @bdd_framework.test
32
+ end
33
+
34
+ end
@@ -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"
@@ -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
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
  require 'spec/runner/formatter/progress_bar_formatter'
3
3
 
4
4
  # Example of a formatter with custom bactrace printing. Run me with:
5
- # ruby bin/spec examples/failing -r examples/custom_formatter.rb -f CustomFormatter
5
+ # ruby bin/spec examples/failing -r examples/passing/custom_formatter.rb -f CustomFormatter
6
6
  class CustomFormatter < Spec::Runner::Formatter::ProgressBarFormatter
7
7
  def backtrace_line(line)
8
8
  line.gsub(/([^:]*\.rb):(\d*)/) do
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "arrays" do
4
+ def contain_same_elements_as(expected)
5
+ simple_matcher "array with same elements in any order as #{expected.inspect}" do |actual|
6
+ if actual.size == expected.size
7
+ a, e = actual.dup, expected.dup
8
+ until e.empty? do
9
+ if i = a.index(e.pop) then a.delete_at(i) end
10
+ end
11
+ a.empty?
12
+ else
13
+ false
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "can be matched by their contents disregarding order" do
19
+ subject { [1,2,2,3] }
20
+ it { should contain_same_elements_as([1,2,2,3]) }
21
+ it { should contain_same_elements_as([2,3,2,1]) }
22
+ it { should_not contain_same_elements_as([3,3,2,1]) }
23
+ end
24
+
25
+ describe "fail the match with different contents" do
26
+ subject { [1,2,3] }
27
+ it { should_not contain_same_elements_as([2,3,4])}
28
+ it { should_not contain_same_elements_as([1,2,2,3])}
29
+ it { should_not contain_same_elements_as([1,2])}
30
+ end
31
+ end
@@ -21,7 +21,7 @@ class Autotest::Rspec < Autotest
21
21
 
22
22
  def initialize
23
23
  super
24
- self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
24
+ self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
25
25
  self.completed_re = /\n(?:\e\[\d*m)?\d* examples?/m
26
26
  end
27
27
 
@@ -0,0 +1,82 @@
1
+ module Spec
2
+ module DSL
3
+ module Main
4
+ # Creates and returns a class that includes the ExampleGroupMethods
5
+ # module. Which ExampleGroup type is created depends on the directory of the file
6
+ # calling this method. For example, Spec::Rails will use different
7
+ # classes for specs living in <tt>spec/models</tt>,
8
+ # <tt>spec/helpers</tt>, <tt>spec/views</tt> and
9
+ # <tt>spec/controllers</tt>.
10
+ #
11
+ # It is also possible to override autodiscovery of the example group
12
+ # type with an options Hash as the last argument:
13
+ #
14
+ # describe "name", :type => :something_special do ...
15
+ #
16
+ # The reason for using different behaviour classes is to have different
17
+ # matcher methods available from within the <tt>describe</tt> block.
18
+ #
19
+ # See Spec::Example::ExampleGroupFactory#register for details about how to
20
+ # register special implementations.
21
+ #
22
+ def describe(*args, &block)
23
+ Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
24
+ end
25
+ alias :context :describe
26
+
27
+ # Creates an example group that can be shared by other example groups
28
+ #
29
+ # == Examples
30
+ #
31
+ # share_examples_for "All Editions" do
32
+ # it "all editions behaviour" ...
33
+ # end
34
+ #
35
+ # describe SmallEdition do
36
+ # it_should_behave_like "All Editions"
37
+ #
38
+ # it "should do small edition stuff" do
39
+ # ...
40
+ # end
41
+ # end
42
+ def share_examples_for(name, &block)
43
+ Spec::Example::SharedExampleGroup.register(name, &block)
44
+ end
45
+ alias :shared_examples_for :share_examples_for
46
+
47
+ # Creates a Shared Example Group and assigns it to a constant
48
+ #
49
+ # share_as :AllEditions do
50
+ # it "should do all editions stuff" ...
51
+ # end
52
+ #
53
+ # describe SmallEdition do
54
+ # it_should_behave_like AllEditions
55
+ #
56
+ # it "should do small edition stuff" do
57
+ # ...
58
+ # end
59
+ # end
60
+ #
61
+ # And, for those of you who prefer to use something more like Ruby, you
62
+ # can just include the module directly
63
+ #
64
+ # describe SmallEdition do
65
+ # include AllEditions
66
+ #
67
+ # it "should do small edition stuff" do
68
+ # ...
69
+ # end
70
+ # end
71
+ def share_as(name, &block)
72
+ begin
73
+ Object.const_set(name, Spec::Example::SharedExampleGroup.register(name, &block))
74
+ rescue NameError => e
75
+ raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ include Spec::DSL::Main
data/lib/spec/dsl.rb ADDED
@@ -0,0 +1 @@
1
+ require 'spec/dsl/main'
@@ -27,7 +27,8 @@ module Spec
27
27
  after_parts(*args) << block
28
28
  end
29
29
 
30
- def remove_after(scope, &block)
30
+ # TODO - deprecate this unless there is a reason why it exists
31
+ def remove_after(scope, &block) # :nodoc:
31
32
  after_each_parts.delete(block)
32
33
  end
33
34
 
@@ -145,7 +145,7 @@ module Spec
145
145
  required_example_group = get_type_from_options(options)
146
146
  required_example_group = required_example_group.to_sym if required_example_group
147
147
  modules.each do |mod|
148
- ExampleGroupFactory.get(required_example_group).send(action, mod)
148
+ ExampleGroupFactory.get(required_example_group).__send__(action, mod)
149
149
  end
150
150
  end
151
151
 
@@ -10,6 +10,7 @@ module Spec
10
10
  @_options = options
11
11
  @_defined_description = defined_description
12
12
  @_implementation = implementation || pending_implementation
13
+ @_backtrace = caller
13
14
  end
14
15
 
15
16
  private
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Example
3
3
  class ExampleGroupFactory
4
- class << self
4
+ module ClassMethods
5
5
  def reset
6
6
  @example_group_types = nil
7
7
  default(ExampleGroup)
@@ -76,6 +76,7 @@ module Spec
76
76
  end
77
77
 
78
78
  end
79
+ extend ClassMethods
79
80
  self.reset
80
81
  end
81
82
  end