rspec 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ require 'spec'
2
+
3
+
4
+ class MockTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @mock = Mock.new
8
+ end
9
+
10
+ def test_should_allow_block_to_calculate_return_values
11
+ @mock.__expects(:random_call).with("a","b","c").returns { |a,b,c| c+b+a }
12
+ assert_equal "cba",@mock.random_call("a","b","c")
13
+ @mock.__verify
14
+ end
15
+
16
+ def test_should_allow_parameter_as_return_value
17
+ @mock.__expects(:random_call).with("a","b","c").returns("booh")
18
+ assert_equal "booh",@mock.random_call("a","b","c")
19
+ @mock.__verify
20
+ end
21
+
22
+ def test_return_nil_if_no_return_value_set
23
+ @mock.__expects(:random_call).with("a","b","c")
24
+ assert_nil @mock.random_call("a","b","c")
25
+ @mock.__verify
26
+ end
27
+
28
+ def test_should_test_multiple_calls_to_method_with_same_parameters
29
+ @mock.__expects(:random_call).twice.with("a","b","c")
30
+ @mock.random_call("a","b","c")
31
+ @mock.random_call("a","b","c")
32
+ @mock.__verify
33
+ end
34
+
35
+ def test_should_raise_exception_if_parameters_dont_match_when_method_called
36
+ @mock.__expects(:random_call).with("a","b","c").returns("booh")
37
+ assert_raise(Spec::Exceptions::MockExpectationError) {
38
+ @mock.random_call("a","d","c")
39
+ }
40
+ end
41
+
42
+ def test_should_fail_if_unexpected_method_called
43
+ assert_raise(Spec::Exceptions::MockExpectationError) {
44
+ @mock.random_call("a","d","c")
45
+ }
46
+ end
47
+
48
+ def test_should_allow_unexpected_methods_if_ignore_missing_set
49
+ @mock.ignore_missing
50
+ @mock.random_call("a","d","c")
51
+ end
52
+
53
+ def test_should_raise_exception_on_verify_if_call_counts_not_as_expected
54
+ @mock.__expects(:random_call).twice.with("a","b","c").returns("booh")
55
+ @mock.random_call("a","b","c")
56
+ assert_raise(Spec::Exceptions::MockExpectationError) do
57
+ @mock.__verify
58
+ end
59
+ end
60
+
61
+ def test_should_use_block_for_expectation_if_provided
62
+ @mock.__expects(:random_call) do | a, b |
63
+ a.should_equal("a")
64
+ b.should_equal("b")
65
+ "booh"
66
+ end
67
+ assert_equal("booh", @mock.random_call("a", "b"))
68
+ end
69
+
70
+ def test_failing_expectation_block_throws
71
+ @mock.__expects(:random_call) {| a | a.should_be_true}
72
+ assert_raise(Spec::Exceptions::MockExpectationError) do
73
+ @mock.random_call false
74
+ end
75
+ end
76
+
77
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+
3
+ require 'rspec'
4
+
5
+ $: << 'examples/'
6
+
7
+ class RSpecTest < Test::Unit::TestCase
8
+
9
+ def test_should_load_craps_spec
10
+ rspec = RSpec.new(["examples/craps_spec.rb"])
11
+ assert_equal true, get_classes.include?('CrapsSpecification')
12
+ end
13
+
14
+ def test_should_load_movie_spec
15
+ rspec = RSpec.new(["examples/movie_spec.rb"])
16
+ assert_equal true, get_classes.include?('EmptyMovieList')
17
+ assert_equal true, get_classes.include?('OneMovieList')
18
+ end
19
+
20
+ def test_should_load_craps_and_movie_specs
21
+ rspec = RSpec.new(["examples/craps_spec.rb", "examples/movie_spec.rb"])
22
+ assert_equal true, get_classes.include?('CrapsSpecification')
23
+ assert_equal true, get_classes.include?('EmptyMovieList')
24
+ assert_equal true, get_classes.include?('OneMovieList')
25
+ end
26
+
27
+ private
28
+
29
+ def get_classes
30
+ classes = []
31
+ ObjectSpace.each_object(Class) {|cls| classes << cls.to_s}
32
+ classes
33
+ end
34
+
35
+ end
@@ -0,0 +1,39 @@
1
+ require 'test/unit'
2
+
3
+ require 'spec'
4
+
5
+
6
+ class Foobar < Spec::Context
7
+
8
+ def first_method
9
+ end
10
+
11
+ def second_method
12
+ end
13
+
14
+ end
15
+
16
+
17
+ class SpecCollectionTest < Test::Unit::TestCase
18
+
19
+ def setup
20
+ @collection = Foobar.collection
21
+ end
22
+
23
+ def test_should_have_two_fixtures_in_collection
24
+ assert_equal 2, @collection.length
25
+ end
26
+
27
+ def test_should_include_first_method_fixture
28
+ assert_equal true, @collection.any? do |spec|
29
+ spec.instance_variable_get(:@specification) == :first_method
30
+ end
31
+ end
32
+
33
+ def test_should_include_second_method_fixture
34
+ assert_equal true, @collection.any? do |spec|
35
+ spec.instance_variable_get(:@specification) == :second_method
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,71 @@
1
+ require 'test/unit'
2
+
3
+ require 'spec'
4
+
5
+
6
+ class SpecificationIdentificationContext < Spec::Context
7
+
8
+ def setup
9
+ end
10
+
11
+ def teardown
12
+ end
13
+
14
+ def foo
15
+ end
16
+
17
+ def bar
18
+ end
19
+
20
+ def baz(arg1, arg2)
21
+ end
22
+
23
+ def _method_with_underscore
24
+ end
25
+
26
+ end
27
+
28
+
29
+ class ContextTest < Test::Unit::TestCase
30
+
31
+ def setup
32
+ @spec_id_context = SpecificationIdentificationContext.new
33
+ end
34
+
35
+ def test_should_inherit_from_context
36
+ assert_equal Spec::Context, @spec_id_context.class.superclass
37
+ end
38
+
39
+ def test_should_contain_two_specifications
40
+ assert_equal 2, SpecificationIdentificationContext.specifications.length
41
+ end
42
+
43
+ def test_should_have_foo_specification
44
+ assert_equal true, SpecificationIdentificationContext.specifications.include?('foo')
45
+ end
46
+
47
+ def test_should_have_bar_specification
48
+ assert_equal true, SpecificationIdentificationContext.specifications.include?('bar')
49
+ end
50
+
51
+ def test_should_not_include_specifications_method_in_specifications
52
+ assert_equal false, SpecificationIdentificationContext.specifications.include?('specifications')
53
+ end
54
+
55
+ def test_should_not_include_setup_in_specifications
56
+ assert_equal false, SpecificationIdentificationContext.specifications.include?(:setup)
57
+ end
58
+
59
+ def test_should_not_include_teardown_in_specifications
60
+ assert_equal false, SpecificationIdentificationContext.specifications.include?(:teardown)
61
+ end
62
+
63
+ def test_should_not_include_methods_with_args_in_specifications
64
+ assert_equal false, SpecificationIdentificationContext.specifications.include?('baz')
65
+ end
66
+
67
+ def test_should_not_include_methods_prefixed_with_underscore_in_specifications
68
+ assert_equal false, SpecificationIdentificationContext.specifications.include?('_method_with_underscore')
69
+ end
70
+
71
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ module Foo
4
+ class BarSpec < Spec::Context
5
+ def should_fail
6
+ raise "ERRORRRR"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,111 @@
1
+ require 'test/unit'
2
+
3
+ require 'spec'
4
+
5
+ class PassingCon < Spec::Context
6
+
7
+ def ex1
8
+ true.should_be_true
9
+ end
10
+
11
+ def ex2
12
+ true.should_be_true
13
+ end
14
+
15
+ def ex3
16
+ true.should_be_true
17
+ end
18
+
19
+ end
20
+
21
+
22
+ class FailingCon < Spec::Context
23
+
24
+ def fail1
25
+ false.should_be_true
26
+ end
27
+
28
+ def fail2
29
+ false.should_be_true
30
+ end
31
+
32
+ def fail3
33
+ false.should_be_true
34
+ end
35
+
36
+ end
37
+
38
+
39
+ class ErringCon < Spec::Context
40
+
41
+ def error1
42
+ raise "boom"
43
+ end
44
+
45
+ def error2
46
+ raise "boom"
47
+ end
48
+
49
+ def error3
50
+ raise "boom"
51
+ end
52
+
53
+ end
54
+
55
+
56
+ class TestTextRunner < Test::Unit::TestCase
57
+
58
+ def setup
59
+ @buffer = String.new
60
+ @runner = Spec::TextRunner.new(@buffer)
61
+ end
62
+
63
+ def test_passing_example_outputs_period
64
+ @runner.run(PassingCon)
65
+ assert_buffer_includes("...")
66
+ end
67
+
68
+ def test_failing_example_outputs_X
69
+ @runner.run(FailingCon)
70
+ assert_buffer_includes("XXX")
71
+ end
72
+
73
+ def test_erring_example_outputs_X
74
+ @runner.run(ErringCon)
75
+ assert_buffer_includes("XXX")
76
+ end
77
+
78
+ def test_failure_backtrace
79
+ @runner.run(FailingCon)
80
+ assert_buffer_includes("1)")
81
+ assert_buffer_includes("in `fail1'")
82
+ assert_buffer_includes("2)")
83
+ assert_buffer_includes("in `fail2'")
84
+ assert_buffer_includes("3)")
85
+ assert_buffer_includes("in `fail3'")
86
+ end
87
+
88
+ def test_error_backtrace
89
+ @runner.run(ErringCon)
90
+ assert_buffer_includes "1)"
91
+ assert_buffer_includes "in `error1'"
92
+ assert_buffer_includes "2)"
93
+ assert_buffer_includes "in `error2'"
94
+ assert_buffer_includes "3)"
95
+ assert_buffer_includes "in `error3'"
96
+ end
97
+
98
+ def test_summary_with_no_failures
99
+ @runner.run(PassingCon)
100
+ assert_buffer_includes "3 specifications, 3 expectations, 0 failures"
101
+ end
102
+
103
+ def assert_buffer_includes(substring)
104
+ assert(@buffer.include?(substring), _buffer_message(substring))
105
+ end
106
+
107
+ def _buffer_message(substring)
108
+ "Expected substring <" + substring + "> Buffer was <" + @buffer + ">"
109
+ end
110
+
111
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.10
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2005-08-14
6
+ version: 0.1.5
7
+ date: 2005-08-16 00:00:00 -04:00
8
8
  summary: Behaviour Specification Framework for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -27,6 +27,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
27
27
  version: 0.0.0
28
28
  version:
29
29
  platform: ruby
30
+ signing_key:
31
+ cert_chain:
30
32
  authors:
31
33
  - Steven Baker
32
34
  files:
@@ -41,6 +43,21 @@ files:
41
43
  - lib/spec/expectations.rb
42
44
  - lib/spec/mock.rb
43
45
  - lib/spec/text_runner.rb
46
+ - test/context_fixtures_test.rb
47
+ - test/context_run_test.rb
48
+ - test/error_reporting_test.rb
49
+ - test/expectations_test.rb
50
+ - test/mock_test.rb
51
+ - test/rspec_test.rb
52
+ - test/spec_collection_test.rb
53
+ - test/specification_identification_test.rb
54
+ - test/test_unit_ext_spec.rb
55
+ - test/text_runner_test.rb
56
+ - examples/craps.rb
57
+ - examples/craps_spec.rb
58
+ - examples/movie.rb
59
+ - examples/movie_list.rb
60
+ - examples/movie_spec.rb
44
61
  test_files: []
45
62
  rdoc_options:
46
63
  - "--title"