dchelimsky-rspec 1.1.10 → 1.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/History.txt +17 -0
  2. data/Manifest.txt +53 -74
  3. data/Rakefile +0 -1
  4. data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
  5. data/examples/{pure → passing}/before_and_after_example.rb +0 -0
  6. data/examples/{pure → passing}/behave_as_example.rb +0 -0
  7. data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
  8. data/examples/{pure → passing}/custom_formatter.rb +1 -1
  9. data/examples/{pure → passing}/dynamic_spec.rb +2 -2
  10. data/examples/{pure → passing}/file_accessor.rb +0 -0
  11. data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
  12. data/examples/{pure → passing}/greeter_spec.rb +0 -0
  13. data/examples/{pure → passing}/helper_method_example.rb +0 -0
  14. data/examples/{pure → passing}/io_processor.rb +0 -0
  15. data/examples/{pure → passing}/io_processor_spec.rb +0 -0
  16. data/examples/{pure → passing}/legacy_spec.rb +0 -0
  17. data/examples/{pure → passing}/mocking_example.rb +0 -0
  18. data/examples/{pure → passing}/multi_threaded_behaviour_runner.rb +0 -0
  19. data/examples/{pure → passing}/nested_classes_example.rb +0 -0
  20. data/examples/{pure → passing}/partial_mock_example.rb +0 -0
  21. data/examples/{pure → passing}/pending_example.rb +0 -0
  22. data/examples/{pure → passing}/predicate_example.rb +0 -0
  23. data/examples/{pure → passing}/priority.txt +0 -0
  24. data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
  25. data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
  26. data/examples/{pure → passing}/spec_helper.rb +0 -0
  27. data/examples/{pure → passing}/stack.rb +0 -0
  28. data/examples/{pure → passing}/stack_spec.rb +3 -2
  29. data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
  30. data/examples/{pure → passing}/stubbing_example.rb +0 -0
  31. data/examples/{pure → passing}/yielding_example.rb +0 -0
  32. data/lib/spec/example/before_and_after_hooks.rb +8 -21
  33. data/lib/spec/example/configuration.rb +45 -45
  34. data/lib/spec/example/example_group_factory.rb +10 -9
  35. data/lib/spec/example/example_group_methods.rb +31 -15
  36. data/lib/spec/example/example_methods.rb +74 -22
  37. data/lib/spec/example/shared_example_group.rb +27 -16
  38. data/lib/spec/example.rb +28 -0
  39. data/lib/spec/expectations.rb +1 -0
  40. data/lib/spec/extensions.rb +0 -2
  41. data/lib/spec/matchers/be.rb +96 -114
  42. data/lib/spec/matchers/operator_matcher.rb +2 -9
  43. data/lib/spec/matchers/throw_symbol.rb +41 -15
  44. data/lib/spec/matchers.rb +4 -27
  45. data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
  46. data/lib/spec/runner/option_parser.rb +2 -2
  47. data/lib/spec/runner/reporter.rb +1 -1
  48. data/lib/spec/runner.rb +1 -1
  49. data/lib/spec/version.rb +1 -1
  50. data/lib/spec.rb +1 -0
  51. data/rspec.gemspec +4 -24
  52. data/spec/spec/example/example_group_factory_spec.rb +29 -9
  53. data/spec/spec/example/example_group_methods_spec.rb +4 -6
  54. data/spec/spec/example/example_group_spec.rb +0 -6
  55. data/spec/spec/example/example_matcher_spec.rb +6 -23
  56. data/spec/spec/example/example_methods_spec.rb +117 -2
  57. data/spec/spec/example/shared_example_group_spec.rb +51 -75
  58. data/spec/spec/matchers/be_spec.rb +40 -7
  59. data/spec/spec/matchers/description_generation_spec.rb +14 -0
  60. data/spec/spec/matchers/throw_symbol_spec.rb +83 -41
  61. data/spec/spec/runner/command_line_spec.rb +4 -4
  62. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
  63. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
  64. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
  65. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
  66. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +6 -6
  67. data/spec/spec/runner/formatter/html_formatter_spec.rb +1 -1
  68. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +5 -5
  69. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
  70. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +6 -6
  71. data/spec/spec/runner/reporter_spec.rb +1 -1
  72. data/stories/example_groups/autogenerated_docstrings +4 -4
  73. data/stories/example_groups/nested_groups +2 -2
  74. metadata +33 -59
  75. data/examples/stories/adder.rb +0 -13
  76. data/examples/stories/addition +0 -34
  77. data/examples/stories/addition.rb +0 -9
  78. data/examples/stories/calculator.rb +0 -65
  79. data/examples/stories/game-of-life/.loadpath +0 -5
  80. data/examples/stories/game-of-life/README.txt +0 -21
  81. data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
  82. data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
  83. data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
  84. data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
  85. data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
  86. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
  87. data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
  88. data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
  89. data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
  90. data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
  91. data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
  92. data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
  93. data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
  94. data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
  95. data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
  96. data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
  97. data/examples/stories/game-of-life/life/game.rb +0 -23
  98. data/examples/stories/game-of-life/life/grid.rb +0 -43
  99. data/examples/stories/game-of-life/life.rb +0 -3
  100. data/examples/stories/helper.rb +0 -9
  101. data/examples/stories/steps/addition_steps.rb +0 -18
  102. data/failing_examples/README.txt +0 -7
  103. data/failing_examples/diffing_spec.rb +0 -36
  104. data/failing_examples/failing_autogenerated_docstrings_example.rb +0 -19
  105. data/failing_examples/failure_in_setup.rb +0 -10
  106. data/failing_examples/failure_in_teardown.rb +0 -10
  107. data/failing_examples/mocking_example.rb +0 -40
  108. data/failing_examples/mocking_with_flexmock.rb +0 -26
  109. data/failing_examples/mocking_with_mocha.rb +0 -25
  110. data/failing_examples/mocking_with_rr.rb +0 -27
  111. data/failing_examples/partial_mock_example.rb +0 -20
  112. data/failing_examples/predicate_example.rb +0 -29
  113. data/failing_examples/raising_example.rb +0 -47
  114. data/failing_examples/spec_helper.rb +0 -3
  115. data/failing_examples/syntax_error_example.rb +0 -7
  116. data/failing_examples/team_spec.rb +0 -44
  117. data/failing_examples/timeout_behaviour.rb +0 -7
  118. data/lib/spec/extensions/main.rb +0 -87
  119. data/lib/spec/extensions/object.rb +0 -6
  120. data/spec/spec/extensions/main_spec.rb +0 -71
@@ -1,3 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[helper])
2
- require 'behaviour/stories/create_a_cell'
3
- require 'behaviour/stories/kill_a_cell'
@@ -1,22 +0,0 @@
1
- Story: Show the game field
2
- As a game player
3
- I want to see the field
4
- so that I can observe the progress of the organisms
5
-
6
- Scenario: an empty field
7
- Given a new game starts
8
- When the game displays the field
9
- Then the field should be empty
10
-
11
-
12
-
13
-
14
-
15
- StoryBuilder story = stories.createStory().called("a story")
16
- .asA("person")
17
- .iWant("to do something")
18
- .soThat("I can rule the world");
19
- story.addScenario().called("happy path").as()
20
- .given("some context")
21
- .when("some event happens")
22
- .then("expect some outcome");
@@ -1,23 +0,0 @@
1
- class Game
2
- attr_accessor :grid
3
- def initialize(rows,cols)
4
- @grid = Grid.new(rows, cols)
5
- end
6
-
7
- def create_at(row,col)
8
- @grid.create_at(row,col)
9
- end
10
-
11
- def destroy_at(row,col)
12
- @grid.destroy_at(row, col)
13
- end
14
-
15
- def self.from_string(dots)
16
- grid = Grid.from_string(dots)
17
- game = new(grid.rows, grid.columns)
18
- game.instance_eval do
19
- @grid = grid
20
- end
21
- return game
22
- end
23
- end
@@ -1,43 +0,0 @@
1
- class Grid
2
-
3
- attr_accessor :contents
4
-
5
- def initialize(rows, cols)
6
- @contents = []
7
- rows.times do @contents << [0] * cols end
8
- end
9
-
10
- def rows
11
- @contents.size
12
- end
13
-
14
- def columns
15
- @contents[0].size
16
- end
17
-
18
- def ==(other)
19
- self.contents == other.contents
20
- end
21
-
22
- def create_at(row,col)
23
- @contents[row][col] = 1
24
- end
25
-
26
- def destroy_at(row,col)
27
- @contents[row][col] = 0
28
- end
29
-
30
- def self.from_string(str)
31
- row_strings = str.split(' ')
32
- grid = new(row_strings.size, row_strings[0].size)
33
-
34
- row_strings.each_with_index do |row, row_index|
35
- row_chars = row.split(//)
36
- row_chars.each_with_index do |col_char, col_index|
37
- grid.create_at(row_index, col_index) if col_char == 'X'
38
- end
39
- end
40
- return grid
41
- end
42
-
43
- end
@@ -1,3 +0,0 @@
1
- $: << File.dirname(__FILE__)
2
- require 'life/game'
3
- require 'life/grid'
@@ -1,9 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
- require 'spec/story'
3
-
4
- # won't have to do this once plain_text_story_runner is moved into the library
5
- # require File.join(File.dirname(__FILE__), "plain_text_story_runner")
6
-
7
- Dir[File.join(File.dirname(__FILE__), "steps/*.rb")].each do |file|
8
- require file
9
- end
@@ -1,18 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
-
3
- # This creates steps for :addition
4
- steps_for(:addition) do
5
- Given("an addend of $addend") do |addend|
6
- @adder ||= Adder.new
7
- @adder << addend.to_i
8
- end
9
- end
10
-
11
- # This appends to them
12
- steps_for(:addition) do
13
- When("the addends are added") { @sum = @adder.sum }
14
- end
15
-
16
- steps_for(:more_addition) do
17
- Then("the sum should be $sum") { |sum| @sum.should == sum.to_i }
18
- end
@@ -1,7 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,19 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,40 +0,0 @@
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
@@ -1,26 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,27 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,29 +0,0 @@
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
- end
@@ -1,47 +0,0 @@
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
@@ -1,3 +0,0 @@
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"
@@ -1,7 +0,0 @@
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
@@ -1,44 +0,0 @@
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
@@ -1,7 +0,0 @@
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
@@ -1,87 +0,0 @@
1
- module Spec
2
- module Extensions
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
- raise ArgumentError if args.empty?
24
- raise ArgumentError unless block
25
- args << {} unless Hash === args.last
26
- args.last[:spec_path] = File.expand_path(caller(0)[1])
27
- Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
28
- end
29
- alias :context :describe
30
-
31
- # Creates an example group that can be shared by other example groups
32
- #
33
- # == Examples
34
- #
35
- # share_examples_for "All Editions" do
36
- # it "all editions behaviour" ...
37
- # end
38
- #
39
- # describe SmallEdition do
40
- # it_should_behave_like "All Editions"
41
- #
42
- # it "should do small edition stuff" do
43
- # ...
44
- # end
45
- # end
46
- def share_examples_for(name, &block)
47
- describe(name, :shared => true, &block)
48
- end
49
-
50
- alias :shared_examples_for :share_examples_for
51
-
52
- # Creates a Shared Example Group and assigns it to a constant
53
- #
54
- # share_as :AllEditions do
55
- # it "should do all editions stuff" ...
56
- # end
57
- #
58
- # describe SmallEdition do
59
- # it_should_behave_like AllEditions
60
- #
61
- # it "should do small edition stuff" do
62
- # ...
63
- # end
64
- # end
65
- #
66
- # And, for those of you who prefer to use something more like Ruby, you
67
- # can just include the module directly
68
- #
69
- # describe SmallEdition do
70
- # include AllEditions
71
- #
72
- # it "should do small edition stuff" do
73
- # ...
74
- # end
75
- # end
76
- def share_as(name, &block)
77
- begin
78
- Object.const_set(name, share_examples_for(name, &block))
79
- rescue NameError => e
80
- raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
81
- end
82
- end
83
- end
84
- end
85
- end
86
-
87
- include Spec::Extensions::Main
@@ -1,6 +0,0 @@
1
- class Object
2
- def args_and_options(*args)
3
- options = Hash === args.last ? args.pop : {}
4
- return args, options
5
- end
6
- end
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- module Spec
4
- module Extensions
5
- describe Main do
6
- before(:each) do
7
- @main = Class.new do; include Main; end
8
- end
9
-
10
- after(:each) do
11
- $rspec_story_steps = @original_rspec_story_steps
12
- end
13
-
14
- [:describe, :context].each do |method|
15
- describe "##{method}" do
16
- specify {@main.should respond_to(method)}
17
-
18
- it "should raise when no block is given to #{method}" do
19
- lambda { @main.__send__ method, "foo" }.should raise_error(ArgumentError)
20
- end
21
-
22
- it "should raise when no description is given to #{method}" do
23
- lambda { @main.__send__ method do; end }.should raise_error(ArgumentError)
24
- end
25
-
26
- it "should run registered ExampleGroups" do
27
- example_group = @main.__send__ method, "The ExampleGroup" do end
28
- Spec::Runner.options.example_groups.should include(example_group)
29
- end
30
-
31
- it "should not run unregistered ExampleGroups" do
32
- example_group = @main.__send__ method, "The ExampleGroup" do unregister; end
33
- Spec::Runner.options.example_groups.should_not include(example_group)
34
- end
35
- end
36
- end
37
-
38
- describe "#share_examples_for" do
39
- it "should create a shared ExampleGroup" do
40
- group = @main.share_examples_for "all things" do end
41
- group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
42
- end
43
- end
44
-
45
- describe "#share_as" do
46
- before(:each) do
47
- $share_as_examples_example_module_number ||= 1
48
- $share_as_examples_example_module_number += 1
49
- @group_name = "Group#{$share_as_examples_example_module_number}"
50
- end
51
-
52
- it "should create a shared ExampleGroup" do
53
- group = @main.share_as @group_name do end
54
- group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
55
- end
56
-
57
- it "should create a constant that points to a Module" do
58
- group = @main.share_as @group_name do end
59
- Object.const_get(@group_name).should equal(group)
60
- end
61
-
62
- it "should bark if you pass it something not-constantizable" do
63
- lambda do
64
- @group = @main.share_as "Non Constant" do end
65
- end.should raise_error(NameError, /The first argument to share_as must be a legal name for a constant/)
66
- end
67
-
68
- end
69
- end
70
- end
71
- end