rspec 0.6.3 → 0.6.4

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 (90) hide show
  1. data/CHANGES +28 -3
  2. data/EXAMPLES.rd +2 -16
  3. data/README +5 -2
  4. data/Rakefile +8 -4
  5. data/bin/spec +1 -0
  6. data/examples/custom_formatter.rb +2 -1
  7. data/examples/helper_method_spec.rb +12 -0
  8. data/examples/{mocking_spec.rb → mocking_example.rb} +0 -0
  9. data/examples/{bdd_framework_spec.rb → predicate_example.rb} +0 -0
  10. data/examples/stubbing_example.rb +28 -0
  11. data/lib/spec.rb +2 -1
  12. data/lib/spec/expectations.rb +7 -0
  13. data/lib/spec/expectations/diff.rb +56 -0
  14. data/lib/spec/expectations/exceptions.rb +6 -0
  15. data/lib/spec/expectations/expectations.rb +19 -0
  16. data/lib/spec/expectations/have_helper.rb +41 -0
  17. data/lib/spec/expectations/helper.rb +4 -0
  18. data/lib/spec/expectations/should_base.rb +52 -0
  19. data/lib/spec/expectations/should_helper.rb +93 -0
  20. data/lib/spec/expectations/should_negator.rb +71 -0
  21. data/lib/spec/{api → expectations}/sugar.rb +8 -8
  22. data/lib/spec/mocks.rb +5 -0
  23. data/lib/spec/{api/mocks → mocks}/argument_expectation.rb +1 -1
  24. data/lib/spec/{api → mocks}/exceptions.rb +3 -5
  25. data/lib/spec/{api/mocks → mocks}/message_expectation.rb +15 -9
  26. data/lib/spec/{api/mocks → mocks}/mock.rb +44 -26
  27. data/lib/spec/{api/mocks → mocks}/order_group.rb +1 -1
  28. data/lib/spec/runner/backtrace_tweaker.rb +4 -1
  29. data/lib/spec/runner/execution_context.rb +13 -4
  30. data/lib/spec/runner/formatter/base_text_formatter.rb +26 -13
  31. data/lib/spec/runner/formatter/html_formatter.rb +1 -1
  32. data/lib/spec/runner/option_parser.rb +6 -2
  33. data/lib/spec/runner/specification.rb +2 -2
  34. data/lib/spec/test_to_spec/ruby2ruby.rb +1 -1
  35. data/lib/spec/version.rb +1 -1
  36. data/test/spec/expectations/arbitrary_operator_test.rb +55 -0
  37. data/test/spec/expectations/arbitrary_predicate_test.rb +163 -0
  38. data/test/spec/{api/helper → expectations}/containment_test.rb +2 -2
  39. data/test/spec/expectations/diff_test.rb +62 -0
  40. data/test/spec/{api/helper → expectations}/identity_test.rb +2 -2
  41. data/test/spec/{api/helper → expectations}/object_equality_test.rb +2 -2
  42. data/test/spec/{api/helper → expectations}/raising_test.rb +5 -5
  43. data/test/spec/{api/helper → expectations}/regex_matching_test.rb +6 -6
  44. data/test/spec/{api/helper → expectations}/should_have_test.rb +11 -2
  45. data/test/spec/{api/helper → expectations}/should_satisfy_test.rb +2 -4
  46. data/test/spec/{api → expectations}/sugar_test.rb +8 -8
  47. data/test/spec/expectations/supported_symbols_test.rb +33 -0
  48. data/test/spec/{api/helper → expectations}/throwing_test.rb +2 -2
  49. data/test/spec/{api/helper → expectations}/true_false_special_case_test.rb +2 -2
  50. data/test/spec/{api/helper → expectations}/typing_test.rb +2 -2
  51. data/test/spec/{api/mocks → mocks}/mock_arg_constraints_test.rb +4 -4
  52. data/test/spec/{api/mocks → mocks}/mock_counts_test.rb +2 -2
  53. data/test/spec/{api/mocks → mocks}/mock_ordering_test.rb +2 -2
  54. data/test/spec/{api/mocks → mocks}/mock_test.rb +22 -7
  55. data/test/spec/{api/mocks → mocks}/null_object_test.rb +8 -2
  56. data/test/spec/runner/backtrace_tweaker_test.rb +21 -19
  57. data/test/spec/runner/context_matching_test.rb +2 -2
  58. data/test/spec/runner/context_runner_test.rb +6 -6
  59. data/test/spec/runner/context_test.rb +1 -1
  60. data/test/spec/runner/execution_context_test.rb +22 -5
  61. data/test/spec/runner/formatter/failure_dump_test.rb +7 -7
  62. data/test/spec/runner/option_parser_test.rb +20 -0
  63. data/test/spec/runner/reporter_test.rb +3 -3
  64. data/test/spec/runner/specification_test.rb +3 -3
  65. data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +4 -4
  66. data/test/spec/test_to_spec/sexp_transformer_test.rb +1 -1
  67. data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +2 -2
  68. data/test/test_classes.rb +21 -1
  69. data/test/test_helper.rb +1 -1
  70. data/vendor/selenium/README.txt +23 -0
  71. data/vendor/selenium/find_rspecs_home_page.rb +23 -0
  72. data/vendor/selenium/rspec_selenium.rb +33 -0
  73. data/vendor/watir/README.txt +32 -0
  74. data/vendor/watir/find_rspecs_home_page.rb +21 -0
  75. data/vendor/watir/find_rspecs_home_page.txt +15 -0
  76. data/vendor/watir/rspec_watir.rb +45 -0
  77. metadata +52 -41
  78. data/examples/airport_spec.rb +0 -33
  79. data/examples/custom_method_spec.rb +0 -24
  80. data/examples/sugar_spec.rb +0 -14
  81. data/lib/spec/api.rb +0 -8
  82. data/lib/spec/api/expectations.rb +0 -17
  83. data/lib/spec/api/helper.rb +0 -4
  84. data/lib/spec/api/helper/diff.rb +0 -54
  85. data/lib/spec/api/helper/have_helper.rb +0 -40
  86. data/lib/spec/api/helper/should_base.rb +0 -31
  87. data/lib/spec/api/helper/should_helper.rb +0 -93
  88. data/lib/spec/api/helper/should_negator.rb +0 -72
  89. data/test/spec/api/helper/arbitrary_predicate_test.rb +0 -112
  90. data/test/spec/api/helper/diff_test.rb +0 -60
@@ -1,33 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/spec'
2
-
3
- class Airport
4
- def working?
5
- true
6
- end
7
-
8
- def need?(thing)
9
- false unless [:cables, :electricity].include? thing
10
- end
11
- end
12
-
13
- context "Airport at home" do
14
- setup do
15
- @airport = Airport.new
16
- end
17
-
18
- specify "should always work" do
19
- @airport.should_be_working
20
- end
21
-
22
- specify "not need cables" do
23
- @airport.should_not_need :cables
24
- end
25
-
26
- specify "not need electricity" do
27
- @airport.should_not_need :electricity
28
- end
29
-
30
- teardown do
31
- @airport = nil
32
- end
33
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/spec'
2
-
3
- context "Rspec allow you to define custom methods" do
4
- specify "Rspec should allow you to define methods" do
5
- a_method
6
- @a_method_called.should_be true
7
- end
8
-
9
- def a_method
10
- @a_method_called = true
11
- end
12
- end
13
- require File.dirname(__FILE__) + '/../lib/spec'
14
-
15
- context "Rspec allow you to define custom methods" do
16
- specify "Rspec should allow you to define methods" do
17
- a_method
18
- @a_method_called.should_be true
19
- end
20
-
21
- def a_method
22
- @a_method_called = true
23
- end
24
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + '/../lib/spec'
2
-
3
- context "Underscore sugar" do
4
- specify "should be available for regular objects" do
5
- 1.should_equal 1
6
- lambda { 1.should_not_equal 1 }.should_raise
7
- end
8
-
9
- specify "should be available for mocks" do
10
- sweetened = mock "sweetened"
11
- sweetened.should_receive :salt
12
- sweetened.salt
13
- end
14
- end
@@ -1,8 +0,0 @@
1
- require 'spec/api/exceptions'
2
- require 'spec/api/mocks/argument_expectation'
3
- require 'spec/api/mocks/order_group'
4
- require 'spec/api/mocks/message_expectation'
5
- require 'spec/api/mocks/mock'
6
- require 'spec/api/expectations'
7
- require 'spec/api/helper'
8
- require 'spec/api/sugar'
@@ -1,17 +0,0 @@
1
- module Spec
2
- module ObjectExpectations
3
- def should
4
- ShouldHelper.new self
5
- end
6
- end
7
- end
8
-
9
- class Object
10
- include Spec::ObjectExpectations
11
- end
12
-
13
- class Numeric
14
- def close?(other, precision)
15
- (self - other).abs < precision
16
- end
17
- end
@@ -1,4 +0,0 @@
1
- require 'spec/api/helper/should_base'
2
- require 'spec/api/helper/have_helper'
3
- require 'spec/api/helper/should_helper'
4
- require 'spec/api/helper/should_negator'
@@ -1,54 +0,0 @@
1
- begin
2
- require 'rubygems'
3
- require 'diff/lcs' #necessary to do loading bug on some machines - not sure why - DaC
4
- require 'diff/lcs/hunk'
5
- rescue LoadError
6
- raise "You must gem install diff-lcs to use this feature"
7
- end
8
-
9
- module Spec
10
- class ShouldBase
11
- unless defined?(RSPEC_TESTING)
12
- alias old_default_message default_message
13
- def default_message(expectation, expected=:no_expectation_specified)
14
- result = old_default_message(expectation, expected)
15
- if expected.is_a?(String)
16
- result << "\nDiff:" << diff_as_string(@target.to_s, expected)
17
- end
18
- result
19
- end
20
- end
21
-
22
- # This is snagged from diff/lcs/ldiff.rb (which is a commandline tool)
23
- def diff_as_string(data_old, data_new, format=:unified, context_lines=3)
24
- data_old = data_old.split(/\n/).map! { |e| e.chomp }
25
- data_new = data_new.split(/\n/).map! { |e| e.chomp }
26
- output = ""
27
- diffs = Diff::LCS.diff(data_old, data_new)
28
- return output if diffs.empty?
29
- oldhunk = hunk = nil
30
- file_length_difference = 0
31
- diffs.each do |piece|
32
- begin
33
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, context_lines,
34
- file_length_difference)
35
- file_length_difference = hunk.file_length_difference
36
- next unless oldhunk
37
- # Hunks may overlap, which is why we need to be careful when our
38
- # diff includes lines of context. Otherwise, we might print
39
- # redundant lines.
40
- if (context_lines > 0) and hunk.overlaps?(oldhunk)
41
- hunk.unshift(oldhunk)
42
- else
43
- output << oldhunk.diff(format)
44
- end
45
- ensure
46
- oldhunk = hunk
47
- output << "\n"
48
- end
49
- end
50
- #Handle the last remaining hunk
51
- output << oldhunk.diff(format) << "\n"
52
- end
53
- end
54
- end
@@ -1,40 +0,0 @@
1
- module Spec
2
-
3
- class HaveHelper < ShouldBase
4
-
5
- def initialize(target, relativity=:exactly, expected=nil)
6
- @target = target
7
- @expected = expected == :no ? 0 : expected
8
- @at_least = (relativity == :at_least)
9
- @at_most = (relativity == :at_most)
10
- end
11
-
12
- def method_missing(sym, *args)
13
- fail_with_message(build_message(sym)) unless as_specified?(sym)
14
- end
15
-
16
- def collection(sym)
17
- @target.send(sym)
18
- end
19
-
20
- def actual_size(collection)
21
- return collection.length if collection.respond_to? :length
22
- return collection.size if collection.respond_to? :size
23
- end
24
-
25
- def build_message(sym)
26
- message = "<#{@target.class.to_s}> should have"
27
- message += " at least" if @at_least
28
- message += " at most" if @at_most
29
- message += " #{@expected} #{sym} (has #{actual_size(collection(sym))})"
30
- end
31
-
32
- def as_specified?(sym)
33
- return actual_size(collection(sym)) >= @expected if @at_least
34
- return actual_size(collection(sym)) <= @expected if @at_most
35
- return actual_size(collection(sym)) == @expected
36
- end
37
-
38
- end
39
-
40
- end
@@ -1,31 +0,0 @@
1
- class TrueClass; def inspect_for_expectation_not_met_error; "<true>" end end
2
- class FalseClass; def inspect_for_expectation_not_met_error; "<false>" end end
3
- class NilClass; def inspect_for_expectation_not_met_error; "nil" end end
4
- class Class; def inspect_for_expectation_not_met_error; "<#{name}>" end end
5
- class Proc; def inspect_for_expectation_not_met_error; "<Proc>" end end
6
- class Array; def inspect_for_expectation_not_met_error; inspect end end
7
- class String; def inspect_for_expectation_not_met_error; inspect end end
8
- class Object
9
- def inspect_for_expectation_not_met_error
10
- return "#{self.class} #{inspect}" if inspect.include? "<"
11
- return "#{self.class} <#{inspect}>" unless inspect.include? "<"
12
- end
13
- end
14
-
15
- module Spec
16
- class ShouldBase
17
-
18
- def default_message(expectation, expected=:no_expectation_specified)
19
- message = "#{@target.inspect_for_expectation_not_met_error} #{expectation}"
20
- if (expected != :no_expectation_specified)
21
- message << " " << expected.inspect_for_expectation_not_met_error
22
- end
23
- message
24
- end
25
-
26
- def fail_with_message(message)
27
- Kernel::raise(Spec::Api::ExpectationNotMetError.new(message))
28
- end
29
-
30
- end
31
- end
@@ -1,93 +0,0 @@
1
- module Spec
2
-
3
- class ShouldHelper < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- @be_seen = false
8
- end
9
-
10
- def not
11
- ShouldNegator.new(@target)
12
- end
13
-
14
- def have(expected_number=nil)
15
- HaveHelper.new(@target, :exactly, expected_number)
16
- end
17
-
18
- def have_exactly(expected_number=nil)
19
- HaveHelper.new(@target, :exactly, expected_number)
20
- end
21
-
22
- def have_at_least(expected_number=nil)
23
- HaveHelper.new(@target, :at_least, expected_number)
24
- end
25
-
26
- def have_at_most(expected_number=nil)
27
- HaveHelper.new(@target, :at_most, expected_number)
28
- end
29
-
30
- def satisfy(&block)
31
- return if block.call(@target)
32
- fail_with_message "Supplied expectation was not satisfied"
33
- end
34
-
35
- def equal(expected)
36
- fail_with_message(default_message("should equal", expected)) unless (@target == expected)
37
- end
38
-
39
- def be(expected = :___no_arg)
40
- @be_seen = true
41
- return self if (expected == :___no_arg)
42
- return if (expected == false and @target.nil?)
43
- return if (expected == true and (!@target.nil?) and (@target != false))
44
- fail_with_message(default_message("should be", expected)) unless (@target.equal?(expected))
45
- end
46
-
47
- def an_instance_of expected_class
48
- fail_with_message(default_message("should be an instance of", expected_class)) unless @target.instance_of? expected_class
49
- end
50
-
51
- def a_kind_of expected_class
52
- fail_with_message(default_message("should be a kind of", expected_class)) unless @target.kind_of? expected_class
53
- end
54
-
55
- def respond_to message
56
- fail_with_message(default_message("should respond to", message)) unless @target.respond_to? message
57
- end
58
-
59
- def method_missing(sym, *args)
60
- return if @target.send("#{sym}?", *args)
61
- fail_with_message(default_message("should be #{sym}" + (args.empty? ? '' : (' ' + args.join(', '))))) if @be_seen
62
- fail_with_message(default_message("should #{sym}" + (args.empty? ? '' : (' ' + args.join(', '))))) unless @be_seen
63
- end
64
-
65
- def match(expected)
66
- fail_with_message(default_message("should match", expected)) unless (@target =~ expected)
67
- end
68
-
69
- def raise(exception=Exception, message=nil)
70
- begin
71
- @target.call
72
- rescue exception => e
73
- e.message.should_equal message unless message.nil?
74
- return
75
- rescue => e
76
- fail_with_message("#{default_message("should raise", exception)} but raised #{e.inspect}")
77
- end
78
- fail_with_message("#{default_message("should raise", exception)} but raised nothing")
79
- end
80
-
81
- def throw(symbol)
82
- begin
83
- catch symbol do
84
- @target.call
85
- fail_with_message(default_message("should throw", symbol.inspect))
86
- end
87
- rescue NameError
88
- fail_with_message(default_message("should throw", symbol.inspect))
89
- end
90
- end
91
-
92
- end
93
- end
@@ -1,72 +0,0 @@
1
- module Spec
2
-
3
- class ShouldNegator < ShouldBase
4
-
5
- def initialize(target)
6
- @target = target
7
- @be_seen = false
8
- end
9
-
10
- def satisfy
11
- fail_with_message "Supplied expectation was satisfied, but should not have been" if (yield @target)
12
- end
13
-
14
- def equal(expected)
15
- fail_with_message(default_message("should not equal", expected)) if (@target == expected)
16
- end
17
-
18
- def be(expected = :no_arg)
19
- @be_seen = true
20
- return self if (expected == :no_arg)
21
- fail_with_message(default_message("should not be", expected)) if (@target.equal?(expected))
22
- end
23
-
24
- def an_instance_of expected_class
25
- fail_with_message(default_message("should not be an instance of", expected_class)) if @target.instance_of? expected_class
26
- end
27
-
28
- def a_kind_of expected_class
29
- fail_with_message(default_message("should not be a kind of", expected_class)) if @target.kind_of? expected_class
30
- end
31
-
32
- def respond_to message
33
- fail_with_message(default_message("should not respond to", message)) if @target.respond_to? message
34
- end
35
-
36
- def match(expected)
37
- fail_with_message(default_message("should not match", expected)) if (@target =~ expected)
38
- end
39
-
40
- def raise(exception=Exception, message=nil)
41
- begin
42
- @target.call
43
- rescue exception => e
44
- return unless message.nil? || e.message == message
45
- fail_with_message("#{default_message("should not raise", exception)}") if e.instance_of? exception
46
- fail_with_message("#{default_message("should not raise", exception)} but raised #{e.inspect}") unless e.instance_of? exception
47
- rescue
48
- true
49
- end
50
- end
51
-
52
- def throw(symbol=:___this_is_a_symbol_that_will_never_occur___)
53
- begin
54
- catch symbol do
55
- @target.call
56
- return true
57
- end
58
- fail_with_message(default_message("should not throw", symbol.inspect))
59
- rescue NameError
60
- true
61
- end
62
- end
63
-
64
- def method_missing(sym, *args)
65
- return unless @target.send("#{sym}?", *args)
66
- fail_with_message(default_message("should not #{sym}" + (args.empty? ? '' : (' ' + args.join(', '))))) unless @be_seen
67
- fail_with_message(default_message("should not be #{sym}" + (args.empty? ? '' : (' ' + args.join(', '))))) if @be_seen
68
- end
69
-
70
- end
71
-
72
- end
@@ -1,112 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper'
2
-
3
- module Spec
4
- module Api
5
- module Helper
6
-
7
- class ArbitraryPredicateTest < Test::Unit::TestCase
8
-
9
- # should_be_funny
10
-
11
- def test_should_be_funny_should_raise_when_target_doesnt_understand_funny
12
- assert_raise(NoMethodError) do
13
- 5.should_be_funny
14
- end
15
- end
16
-
17
- def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_false
18
- mock = HandCodedMock.new(false)
19
- assert_raise(ExpectationNotMetError) do
20
- mock.should_be_funny
21
- end
22
- mock.__verify
23
- end
24
-
25
- def test_should_be_funny_should_raise_when_sending_funny_to_target_returns_nil
26
- mock = HandCodedMock.new(nil)
27
- assert_raise(ExpectationNotMetError) do
28
- mock.should_be_funny
29
- end
30
- mock.__verify
31
- end
32
-
33
- def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_true
34
- mock = HandCodedMock.new(true)
35
- assert_nothing_raised do
36
- mock.should_be_funny
37
- end
38
- mock.__verify
39
- end
40
-
41
- def test_should_be_funny_should_not_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
42
- mock = HandCodedMock.new(5)
43
- assert_nothing_raised do
44
- mock.should_be_funny
45
- end
46
- mock.__verify
47
- end
48
-
49
- # should_be_funny(args)
50
-
51
- def test_should_be_funny_with_args_passes_args_properly
52
- mock = HandCodedMock.new(true)
53
- assert_nothing_raised do
54
- mock.should_be_hungry(1, 2, 3)
55
- end
56
- mock.__verify
57
- end
58
-
59
- # should_not_be_funny
60
-
61
- def test_should_not_be_funny_should_raise_when_target_doesnt_understand_funny
62
- assert_raise(NoMethodError) do
63
- 5.should_not_be_funny
64
- end
65
- end
66
-
67
- def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_true
68
- mock = HandCodedMock.new(true)
69
- assert_raise(ExpectationNotMetError) do
70
- mock.should_not_be_funny
71
- end
72
- mock.__verify
73
- end
74
-
75
- def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_nil
76
- mock = HandCodedMock.new(nil)
77
- assert_nothing_raised do
78
- mock.should_not_be_funny
79
- end
80
- mock.__verify
81
- end
82
-
83
- def test_should_not_be_funny_shouldnt_raise_when_sending_funny_to_target_returns_false
84
- mock = HandCodedMock.new(false)
85
- assert_nothing_raised do
86
- mock.should_not_be_funny
87
- end
88
- mock.__verify
89
- end
90
-
91
- def test_should_not_be_funny_should_raise_when_sending_funny_to_target_returns_something_other_than_true_false_or_nil
92
- mock = HandCodedMock.new(5)
93
- assert_raise(ExpectationNotMetError) do
94
- mock.should_not_be_funny
95
- end
96
- mock.__verify
97
- end
98
-
99
- # should_be_funny(args)
100
-
101
- def test_should_not_be_funny_with_args_passes_args_properly
102
- mock = HandCodedMock.new(false)
103
- assert_nothing_raised do
104
- mock.should_not_be_hungry(1, 2, 3)
105
- end
106
- mock.__verify
107
- end
108
-
109
- end
110
- end
111
- end
112
- end