rspec 0.5.13 → 0.5.14

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,17 @@
1
1
  = RSpec Changelog
2
2
 
3
+ == Version 0.5.14
4
+ This release introduces better ways to extend specs, improves some of the core API and
5
+ a experimental support for faster rails specs.
6
+
7
+ * Added proc methods for specifying differences (increments and decrements). See difference_test.rb
8
+ * Methods can now be defined alongside specs. This obsoletes the need for defining methods in setup. (Patch #5002 from Brian Takita)
9
+ * Sugar (underscores) now works correctly with should_be_a_kind_of and should_be_an_instance_of
10
+ * Added support for include and inherit in contexts. (Patch #4971 from Brian Takita)
11
+ * Added rails_spec and rails_spec_runner for faster specs on rails (still buggy - help needed)
12
+ * Fixed bug that caused should_render to break if given a :symbol (in Rails)
13
+ * Added support for comparing exception message in should_raise and should_not_raise
14
+
3
15
  == Version 0.5.13
4
16
  This release fixes some subtle bugs in the mock API.
5
17
 
data/EXAMPLES.rd CHANGED
@@ -5,6 +5,11 @@
5
5
  # BDD framework
6
6
  # * should be adopted quickly
7
7
  # * should be intuitive
8
+ # A FileAccessor
9
+ # * should open a file and pass it to the processor's process method
10
+ # An IoProcessor
11
+ # * should raise nothing when the file is exactly 32 bytes
12
+ # * should raise an exception when the file length is less than 32 bytes
8
13
  # Mocker
9
14
  # * should be able to call mock()
10
15
  # An empty stack
data/Rakefile CHANGED
@@ -184,6 +184,7 @@ task :publish_website => [:verify_user, :website] do
184
184
  publisher.upload
185
185
  end
186
186
 
187
+ desc "Build the Rails extension gem"
187
188
  task :package_rails do
188
189
  Dir.chdir 'vendor/rspec_on_rails/vendor/generators/rspec' do
189
190
  `rake clobber gem`
data/bin/spec CHANGED
@@ -7,7 +7,7 @@ $context_runner = ::Spec::Runner::OptionParser.create_context_runner(ARGV, false
7
7
  ARGV.each do |file_or_dir|
8
8
  if File.directory?(file_or_dir)
9
9
  Dir["#{file_or_dir}/**/*.rb"].each do |file|
10
- require "#{file}"
10
+ require file
11
11
  end
12
12
  else
13
13
  require file_or_dir
@@ -10,30 +10,20 @@ class Airport
10
10
  end
11
11
  end
12
12
 
13
- class Spec::Runner::Context
14
- alias should specify
15
- alias must specify
16
- alias fact specify
17
- end
18
- module Kernel
19
- alias topic context
20
- end
21
-
22
- topic "Airport at home" do
13
+ context "Airport at home" do
23
14
  setup do
24
15
  @airport = Airport.new
25
16
  end
26
17
 
27
- fact "should always work" do
18
+ specify "should always work" do
28
19
  @airport.should_be_working
29
20
  end
30
21
 
31
- must "not need cables" do
22
+ specify "not need cables" do
32
23
  @airport.should_not_need :cables
33
24
  end
34
25
 
35
- must "not need electricity" do
36
- # This will fail...
26
+ specify "not need electricity" do
37
27
  @airport.should_not_need :electricity
38
28
  end
39
29
 
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../lib/spec'
2
+ require 'test/unit'
3
+
4
+ class RspecIntegrationTest < Test::Unit::TestCase
5
+ def self.fixtures(*args)
6
+ @@fixtures = true
7
+ end
8
+
9
+ def self.verify_class_method
10
+ @@fixtures.should_be true
11
+ end
12
+
13
+ def setup
14
+ @test_case_setup_called = true
15
+ end
16
+
17
+ def teardown
18
+ @test_case_teardown_called = true
19
+ end
20
+
21
+ def run(result)
22
+ end
23
+
24
+ def helper_method
25
+ @helper_method_called = true
26
+ end
27
+ end
28
+
29
+ module RandomHelperModule
30
+ def random_task
31
+ @random_task_called = true
32
+ end
33
+ end
34
+
35
+ context "Rspec should integrate with Test::Unit::TestCase" do
36
+ inherit RspecIntegrationTest
37
+ include RandomHelperModule
38
+
39
+ fixtures :some_table
40
+
41
+ setup do
42
+ @rspec_setup_called = true
43
+ end
44
+
45
+ specify "TestCase#setup should be called." do
46
+ @test_case_setup_called.should_be true
47
+ @rspec_setup_called.should_be true
48
+ end
49
+
50
+ specify "Rspec should be able to access TestCase methods" do
51
+ helper_method
52
+ @helper_method_called.should_be true
53
+ end
54
+
55
+ specify "Rspec should be able to accept included modules" do
56
+ random_task
57
+ @random_task_called.should_be true
58
+ end
59
+
60
+ teardown do
61
+ RspecIntegrationTest.verify_class_method
62
+ end
63
+ end
@@ -61,10 +61,11 @@ module Spec
61
61
  fail_with_message(default_message("should include", sub)) unless (@target.include? sub)
62
62
  end
63
63
 
64
- def raise(exception=Exception)
64
+ def raise(exception=Exception, message=nil)
65
65
  begin
66
66
  @target.call
67
- rescue exception
67
+ rescue exception => e
68
+ e.message.should.equal message unless message.nil?
68
69
  return
69
70
  rescue => e
70
71
  fail_with_message("#{default_message("should raise", exception)} but raised #{e.inspect}")
@@ -83,6 +84,16 @@ module Spec
83
84
  end
84
85
  end
85
86
 
87
+ def increment(object, method, difference=1)
88
+ initial_value = object.__send__(method)
89
+ @target.call
90
+ object.__send__(method).should.equal(initial_value + difference)
91
+ end
92
+
93
+ def decrement(object, method, difference=1)
94
+ increment(object, method, -difference)
95
+ end
96
+
86
97
  end
87
98
 
88
99
  end
@@ -45,10 +45,11 @@ module Spec
45
45
  fail_with_message(default_message("should not include", sub)) if (@target.include? sub)
46
46
  end
47
47
 
48
- def raise(exception=Exception)
48
+ def raise(exception=Exception, message=nil)
49
49
  begin
50
50
  @target.call
51
51
  rescue exception => e
52
+ return unless message.nil? || e.message == message
52
53
  fail_with_message("#{default_message("should not raise", exception)}") if e.instance_of? exception
53
54
  fail_with_message("#{default_message("should not raise", exception)} but raised #{e.inspect}") unless e.instance_of? exception
54
55
  rescue
@@ -68,6 +69,16 @@ module Spec
68
69
  end
69
70
  end
70
71
 
72
+ def increment(object, method, difference=1)
73
+ initial_value = object.__send__(method)
74
+ @target.call
75
+ object.__send__(method).should.not.equal(initial_value + difference)
76
+ end
77
+
78
+ def decrement(object, method, difference=1)
79
+ increment(object, method, -difference)
80
+ end
81
+
71
82
  def method_missing(sym, *args)
72
83
  return unless @target.send("#{sym}?", *args)
73
84
  fail_with_message(default_message("should not be #{sym}" + (args.empty? ? '' : (' ' + args.join(', ')))))
@@ -10,7 +10,7 @@ module Spec
10
10
  while calls.length > 1
11
11
  call = calls.shift
12
12
  object = object.__send__(call)
13
- break if call == "be"
13
+ break if call == "be" unless ["an","a"].include? calls[0]
14
14
  end
15
15
  return object.__send__(calls.join("_"), *args, &block)
16
16
  end
data/lib/spec/runner.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'spec/runner/formatter'
2
2
  require 'spec/runner/instance_exec'
3
3
  require 'spec/runner/context'
4
+ require 'spec/runner/context_eval'
4
5
  require 'spec/runner/specification'
5
6
  require 'spec/runner/execution_context'
6
7
  require 'spec/runner/context_runner'
@@ -1,52 +1,150 @@
1
1
  module Spec
2
2
  module Runner
3
3
  class Context
4
- def initialize(name, &context_block)
5
- @setup_block = nil
6
- @teardown_block = nil
7
- @specifications = []
8
- @name = name
9
- instance_exec(&context_block)
10
- end
4
+ module InstanceMethods
5
+ def initialize(name, &context_block)
6
+ @name = name
11
7
 
12
- def run(reporter, dry_run=false)
13
- reporter.add_context(@name)
14
- @specifications.each do |specification|
15
- specification.run(reporter, @setup_block, @teardown_block, dry_run)
8
+ @context_eval_module = Module.new
9
+ @context_eval_module.extend ContextEval::ModuleMethods
10
+ @context_eval_module.class_eval &context_block
16
11
  end
17
- end
18
12
 
19
- def setup(&block)
20
- @setup_block = block
21
- end
22
-
23
- def teardown(&block)
24
- @teardown_block = block
25
- end
26
-
27
- def specify(spec_name, &block)
28
- @specifications << Specification.new(spec_name, &block)
29
- end
30
-
31
- def number_of_specs
32
- @specifications.length
33
- end
34
-
35
- def matches? name, matcher=nil
36
- matcher ||= SpecMatcher.new name, @name
37
- @specifications.each do |spec|
38
- return true if spec.matches_matcher? matcher
13
+ def inherit(klass)
14
+ @context_eval_module.inherit klass
39
15
  end
40
- return false
41
- end
42
-
43
- def run_single_spec name
44
- return if @name == name
45
- matcher = SpecMatcher.new name, @name
46
- @specifications.reject! do |spec|
47
- !spec.matches_matcher? matcher
16
+
17
+ def include(mod)
18
+ @context_eval_module.include mod
19
+ end
20
+
21
+ def setup(&block)
22
+ @context_eval_module.setup &block
23
+ end
24
+
25
+ def teardown(&block)
26
+ @context_eval_module.teardown &block
27
+ end
28
+
29
+ def specify(spec_name, &block)
30
+ @context_eval_module.specify spec_name, &block
31
+ end
32
+
33
+ def run(reporter, dry_run=false)
34
+ reporter.add_context(@name)
35
+
36
+ prepare_execution_context_class
37
+ specifications.each do |specification|
38
+ execution_context = execution_context_class.new(specification)
39
+ specification.run(reporter, setup_block, teardown_block, dry_run, execution_context)
40
+ end
41
+ end
42
+
43
+ def number_of_specs
44
+ specifications.length
45
+ end
46
+
47
+ def matches? name, matcher=nil
48
+ matcher ||= SpecMatcher.new name, @name
49
+ specifications.each do |spec|
50
+ return true if spec.matches_matcher? matcher
51
+ end
52
+ return false
53
+ end
54
+
55
+ def run_single_spec name
56
+ return if @name == name
57
+ matcher = SpecMatcher.new name, @name
58
+ specifications.reject! do |spec|
59
+ !spec.matches_matcher? matcher
60
+ end
61
+ end
62
+
63
+ def methods
64
+ my_methods = super
65
+ my_methods |= @context_eval_module.methods
66
+ my_methods
67
+ end
68
+
69
+ protected
70
+
71
+ def method_missing(method_name, *args)
72
+ @context_eval_module.send(method_name, *args)
73
+ end
74
+
75
+ def specifications
76
+ @context_eval_module.send :specifications
77
+ end
78
+
79
+ def setup_block
80
+ @context_eval_module.send :setup_block
81
+ end
82
+ def setup_block=(value)
83
+ @context_eval_module.send :setup_block=, value
84
+ end
85
+
86
+ def teardown_block
87
+ @context_eval_module.send :teardown_block
88
+ end
89
+ def teardown_block=(value)
90
+ @context_eval_module.send :teardown_block=, value
91
+ end
92
+
93
+ def prepare_execution_context_class
94
+ weave_in_context_modules
95
+ weave_in_setup_method
96
+ weave_in_teardown_method
97
+ execution_context_class
98
+ end
99
+
100
+ def weave_in_context_modules
101
+ mods = context_modules
102
+ context_eval_module = @context_eval_module
103
+ execution_context_class.class_eval do
104
+ include context_eval_module
105
+ mods.each do |mod|
106
+ include mod
107
+ end
108
+ end
109
+ end
110
+
111
+ def weave_in_setup_method
112
+ if context_superclass.method_defined?(:setup)
113
+ super_setup = context_superclass.instance_method(:setup)
114
+ context_setup = setup_block if setup_block
115
+
116
+ self.setup_block = proc do
117
+ super_setup.bind(self).call
118
+ instance_exec(&context_setup) if context_setup
119
+ end
120
+ end
121
+ end
122
+
123
+ def weave_in_teardown_method
124
+ if context_superclass.method_defined?(:teardown)
125
+ super_teardown = context_superclass.instance_method(:teardown)
126
+ context_teardown = teardown_block if teardown_block
127
+
128
+ self.teardown_block = proc do
129
+ super_teardown.bind(self).call
130
+ instance_exec(&context_teardown) if context_teardown
131
+ end
132
+ end
133
+ end
134
+
135
+ def context_modules
136
+ @context_eval_module.send :context_modules
137
+ end
138
+
139
+ def execution_context_class
140
+ @context_eval_module.send :execution_context_class
141
+ end
142
+
143
+ def context_superclass
144
+ @context_eval_module.send :context_superclass
48
145
  end
49
146
  end
147
+ include InstanceMethods
50
148
  end
51
149
  end
52
150
  end
@@ -0,0 +1,73 @@
1
+ # Is this file really needed?
2
+ # If I make this an empty file all tests are still passing.
3
+ # But it seems to be used from other files.
4
+ # Can we delete this file?
5
+ module Spec
6
+ module Runner
7
+ module ContextEval
8
+ module ModuleMethods
9
+ def inherit(klass)
10
+ @context_superclass = klass
11
+ derive_execution_context_class_from context_superclass
12
+ end
13
+
14
+ def include(mod)
15
+ context_modules << mod
16
+ end
17
+
18
+ def setup(&block)
19
+ @setup_block = block
20
+ end
21
+
22
+ def teardown(&block)
23
+ @teardown_block = block
24
+ end
25
+
26
+ def specify(spec_name, &block)
27
+ specifications << Specification.new(spec_name, &block)
28
+ end
29
+
30
+ def methods
31
+ my_methods = super
32
+ my_methods |= context_superclass.methods
33
+ my_methods
34
+ end
35
+ protected
36
+
37
+ def method_missing(method_name, *args)
38
+ if context_superclass
39
+ return context_superclass.send(method_name, *args)
40
+ end
41
+ super
42
+ end
43
+
44
+ def specifications
45
+ @specifications ||= []
46
+ end
47
+
48
+ attr_accessor :setup_block
49
+ attr_accessor :teardown_block
50
+
51
+ def derive_execution_context_class_from(context_superclass)
52
+ @execution_context_class = Class.new(context_superclass)
53
+ @execution_context_class.class_eval do
54
+ include ::Spec::Runner::ExecutionContext::InstanceMethods
55
+ end
56
+ end
57
+
58
+ def execution_context_class
59
+ @execution_context_class ||= begin
60
+ derive_execution_context_class_from context_superclass
61
+ end
62
+ end
63
+ def context_superclass
64
+ @context_superclass ||= Object
65
+ end
66
+
67
+ def context_modules
68
+ @context_modules ||= []
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,23 +1,26 @@
1
1
  module Spec
2
2
  module Runner
3
3
  class ExecutionContext
4
- def initialize(spec)
5
- @spec = spec
6
- end
7
-
8
- def mock(name, options={})
9
- mock = Api::Mock.new(name, options)
10
- @spec.add_mock(mock)
11
- mock
12
- end
13
-
14
- def duck_type(*args)
15
- return Api::DuckTypeArgConstraint.new(*args)
16
- end
17
-
18
- def violated(message="")
19
- raise Spec::Api::ExpectationNotMetError.new(message)
4
+ module InstanceMethods
5
+ def initialize(spec)
6
+ @spec = spec
7
+ end
8
+
9
+ def mock(name, options={})
10
+ mock = Api::Mock.new(name, options)
11
+ @spec.add_mock(mock)
12
+ mock
13
+ end
14
+
15
+ def duck_type(*args)
16
+ return Api::DuckTypeArgConstraint.new(*args)
17
+ end
18
+
19
+ def violated(message="")
20
+ raise Spec::Api::ExpectationNotMetError.new(message)
21
+ end
20
22
  end
23
+ include InstanceMethods
21
24
  end
22
25
  end
23
26
  end
@@ -7,13 +7,13 @@ module Spec
7
7
  @block = block
8
8
  @mocks = []
9
9
  end
10
-
11
- def run(reporter=nil, setup_block=nil, teardown_block=nil, dry_run=false)
10
+
11
+ def run(reporter=nil, setup_block=nil, teardown_block=nil, dry_run=false, execution_context=nil)
12
12
  reporter.spec_started(@name)
13
13
  if dry_run
14
14
  reporter.spec_finished(@name)
15
15
  else
16
- execution_context = ::Spec::Runner::ExecutionContext.new(self)
16
+ execution_context = ::Spec::Runner::ExecutionContext.new(self) unless execution_context
17
17
  errors = []
18
18
  begin
19
19
  execution_context.instance_exec(&setup_block) unless setup_block.nil?
@@ -37,7 +37,7 @@ module Spec
37
37
  reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) unless reporter.nil?
38
38
  end
39
39
  end
40
-
40
+
41
41
  def add_mock(mock)
42
42
  @mocks << mock
43
43
  end
data/lib/spec/version.rb CHANGED
@@ -3,7 +3,7 @@ module Spec
3
3
  unless defined? MAJOR
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 13
6
+ TINY = 14
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  TAG = "REL_" + [MAJOR, MINOR, TINY].join('_')
@@ -0,0 +1,78 @@
1
+ require File.dirname(__FILE__) + '/../../../test_helper'
2
+
3
+ module Spec
4
+ module Api
5
+ module Helper
6
+ class ShouldIncrementTest < Test::Unit::TestCase
7
+ def test_should_pass_when_block_increments
8
+ assert_nothing_raised do
9
+ arr = []
10
+ lambda { arr << "something" }.should.increment arr, :length
11
+ end
12
+ end
13
+
14
+ def test_should_pass_when_block_increments_unsing_underscores
15
+ assert_nothing_raised do
16
+ arr = []
17
+ lambda { arr << "something" }.should_increment arr, :length
18
+ end
19
+ end
20
+
21
+ def test_should_fail_when_block_doesnt_increment
22
+ assert_raise(ExpectationNotMetError) do
23
+ arr = []
24
+ lambda {}.should.increment arr, :length
25
+ end
26
+ end
27
+ end
28
+
29
+ class ShouldNotIncrementTest < Test::Unit::TestCase
30
+ def test_should_pass_when_block_doesnt_increment
31
+ assert_nothing_raised do
32
+ arr = []
33
+ lambda {}.should.not.increment arr, :length
34
+ end
35
+ end
36
+
37
+ def test_should_fail_when_block_increments
38
+ assert_raise(ExpectationNotMetError) do
39
+ arr = []
40
+ lambda {arr << "something" }.should.not.increment arr, :length
41
+ end
42
+ end
43
+ end
44
+
45
+ class ShouldDecrementTest < Test::Unit::TestCase
46
+ def test_should_pass_when_block_decrements
47
+ assert_nothing_raised do
48
+ arr = ["something"]
49
+ lambda { arr.pop }.should.decrement arr, :length
50
+ end
51
+ end
52
+
53
+ def test_should_fail_when_block_doesnt_decrement
54
+ assert_raise(ExpectationNotMetError) do
55
+ arr = ["something"]
56
+ lambda {}.should.decrement arr, :length
57
+ end
58
+ end
59
+ end
60
+
61
+ class ShouldNotDecrementTest < Test::Unit::TestCase
62
+ def test_should_pass_when_block_doesnt_decrement
63
+ assert_nothing_raised do
64
+ arr = ["something"]
65
+ lambda {}.should.not.decrement arr, :length
66
+ end
67
+ end
68
+
69
+ def test_should_fail_when_block_decrements
70
+ assert_raise(ExpectationNotMetError) do
71
+ arr = ["something"]
72
+ lambda { arr.pop }.should.not.decrement arr, :length
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -5,19 +5,31 @@ module Spec
5
5
  module Helper
6
6
  class ShouldRaiseTest < Test::Unit::TestCase
7
7
 
8
- def test_should_raise_should_pass_when_exact_exception_is_raised
8
+ def test_should_pass_when_exact_exception_is_raised
9
9
  assert_nothing_raised do
10
10
  proc { ''.nonexistent_method }.should.raise NoMethodError
11
11
  end
12
12
  end
13
13
 
14
- def test_should_raise_should_pass_when_subclass_exception_is_raised
14
+ def test_should_pass_when_exact_exception_is_raised_with_message
15
+ assert_nothing_raised do
16
+ lambda { raise StandardError.new("this is standard") }.should.raise StandardError, "this is standard"
17
+ end
18
+ end
19
+
20
+ def test_should_fail_when_exact_exception_is_raised_with_wrong_message
21
+ assert_raises(Spec::Api::ExpectationNotMetError) do
22
+ lambda { raise StandardError.new("chunky bacon") }.should.raise StandardError, "rotten tomatoes"
23
+ end
24
+ end
25
+
26
+ def test_should_pass_when_subclass_exception_is_raised
15
27
  assert_nothing_raised do
16
28
  proc { ''.nonexistent_method }.should.raise
17
29
  end
18
30
  end
19
31
 
20
- def test_should_raise_should_fail_when_wrong_exception_is_raised
32
+ def test_should_fail_when_wrong_exception_is_raised
21
33
  begin
22
34
  proc { ''.nonexistent_method }.should.raise SyntaxError
23
35
  rescue => e
@@ -25,7 +37,7 @@ module Spec
25
37
  assert_equal("<Proc> should raise <SyntaxError> but raised #<NoMethodError: undefined method `nonexistent_method' for \"\":String>", e.message)
26
38
  end
27
39
 
28
- def test_should_raise_should_fail_when_no_exception_is_raised
40
+ def test_should_fail_when_no_exception_is_raised
29
41
  begin
30
42
  proc { }.should.raise SyntaxError
31
43
  rescue => e
@@ -36,25 +48,37 @@ module Spec
36
48
 
37
49
  class ShouldNotRaiseTest < Test::Unit::TestCase
38
50
 
39
- def test_should_not_raise_should_pass_when_other_exception_is_raised
51
+ def test_should_pass_when_exact_exception_is_raised_with_wrong_message
52
+ assert_nothing_raised do
53
+ lambda { raise StandardError.new("abc") }.should.not.raise StandardError, "xyz"
54
+ end
55
+ end
56
+
57
+ def test_should_faile_when_exact_exception_is_raised_with_message
58
+ assert_raises(Spec::Api::ExpectationNotMetError) do
59
+ lambda { raise StandardError.new("abc") }.should.not.raise StandardError, "abc"
60
+ end
61
+ end
62
+
63
+ def test_should_pass_when_other_exception_is_raised
40
64
  assert_nothing_raised do
41
65
  proc { ''.nonexistent_method }.should.not.raise SyntaxError
42
66
  end
43
67
  end
44
68
 
45
- def test_should_not_raise_should_pass_when_no_exception_is_raised
69
+ def test_should_pass_when_no_exception_is_raised
46
70
  assert_nothing_raised do
47
71
  proc { ''.to_s }.should.not.raise NoMethodError
48
72
  end
49
73
  end
50
74
 
51
- def test_should_not_raise_without_exception_should_pass_when_no_exception_is_raised
75
+ def test_without_exception_should_pass_when_no_exception_is_raised
52
76
  assert_nothing_raised do
53
77
  proc { ''.to_s }.should.not.raise
54
78
  end
55
79
  end
56
80
 
57
- def test_should_not_raise_should_fail_when_specific_exception_is_raised
81
+ def test_should_fail_when_specific_exception_is_raised
58
82
  begin
59
83
  proc { ''.nonexistent_method }.should.not.raise NoMethodError
60
84
  rescue => e
@@ -7,19 +7,19 @@ module Spec
7
7
 
8
8
  def test_should_pass_when_proper_symbol_is_thrown
9
9
  assert_nothing_raised do
10
- proc { throw :foo }.should.throw :foo
10
+ lambda { throw :foo }.should.throw :foo
11
11
  end
12
12
  end
13
13
 
14
14
  def test_should_fail_when_wrong_symbol_is_thrown
15
15
  assert_raise(ExpectationNotMetError) do
16
- proc { throw :bar }.should.throw :foo
16
+ lambda { throw :bar }.should.throw :foo
17
17
  end
18
18
  end
19
19
 
20
20
  def test_should_fail_when_no_symbol_is_thrown
21
21
  assert_raise(ExpectationNotMetError) do
22
- proc { ''.to_s }.should.throw :foo
22
+ lambda { ''.to_s }.should.throw :foo
23
23
  end
24
24
  end
25
25
  end
@@ -28,25 +28,25 @@ module Spec
28
28
 
29
29
  def test_should_fail_when_expected_symbol_is_actually_thrown
30
30
  assert_raise(ExpectationNotMetError) do
31
- proc { throw :foo }.should.not.throw :foo
31
+ lambda { throw :foo }.should.not.throw :foo
32
32
  end
33
33
  end
34
34
 
35
35
  def test_should_pass_when_expected_symbol_is_thrown
36
36
  assert_nothing_raised do
37
- proc { throw :bar }.should.not.throw :foo
37
+ lambda { throw :bar }.should.not.throw :foo
38
38
  end
39
39
  end
40
40
 
41
41
  def test_should_pass_when_no_symbol_is_thrown
42
42
  assert_nothing_raised do
43
- proc { ''.to_s }.should.not.throw :foo
43
+ lambda { ''.to_s }.should.not.throw :foo
44
44
  end
45
45
  end
46
46
 
47
47
  def test_should_pass_when_no_symbol_is_thrown_and_none_is_specified
48
48
  assert_nothing_raised do
49
- proc { ''.to_s }.should.not.throw
49
+ lambda { ''.to_s }.should.not.throw
50
50
  end
51
51
  end
52
52
  end
@@ -59,6 +59,34 @@ module Spec
59
59
  subject.should_not_be_multi_word_predicate
60
60
  end
61
61
  end
62
+
63
+ def test_is_an_instance_of_should_work_when_passing
64
+ n = 10
65
+ assert_nothing_raised do
66
+ n.should_be_an_instance_of Fixnum
67
+ end
68
+ end
69
+
70
+ def test_is_an_instance_of_should_work_when_failing
71
+ n = 10
72
+ assert_raises(Spec::Api::ExpectationNotMetError) do
73
+ n.should_be_an_instance_of String
74
+ end
75
+ end
76
+
77
+ def test_is_a_kind_of_should_work_when_passing
78
+ n = 10
79
+ assert_nothing_raised do
80
+ n.should_be_a_kind_of Numeric
81
+ end
82
+ end
83
+
84
+ def test_is_a_kind_of_should_work_when_failing
85
+ n = 10
86
+ assert_raises(Spec::Api::ExpectationNotMetError) do
87
+ n.should_be_a_kind_of Float
88
+ end
89
+ end
62
90
 
63
91
  end
64
92
  end
@@ -8,11 +8,14 @@ module Spec
8
8
  @formatter = Api::Mock.new "formatter"
9
9
  @context = Context.new("context") {}
10
10
  end
11
+
12
+ def teardown
13
+ @formatter.__verify
14
+ end
11
15
 
12
16
  def test_should_add_itself_to_formatter_on_run
13
17
  @formatter.should.receive(:add_context).with "context"
14
18
  @context.run(@formatter)
15
- @formatter.__verify
16
19
  end
17
20
 
18
21
  def test_should_run_spec
@@ -23,8 +26,7 @@ module Spec
23
26
  @context.specify("test") {$spec_ran = true}
24
27
  @context.run(@formatter)
25
28
  assert $spec_ran
26
- @formatter.__verify
27
- end
29
+ end
28
30
 
29
31
  def test_should_run_spec_dry
30
32
  @formatter.should.receive(:add_context).with :any_args
@@ -34,32 +36,143 @@ module Spec
34
36
  @context.specify("test") {$spec_ran = true}
35
37
  @context.run(@formatter, true)
36
38
  assert !$spec_ran
37
- @formatter.__verify
38
39
  end
39
40
 
40
41
  def test_setup
41
42
  @formatter.should.receive(:add_context).with :any_args
42
43
  @formatter.should.receive(:spec_started).with "test"
43
44
  @formatter.should.receive(:spec_finished).with :any_args
44
- $setup_ran = false
45
- @context.setup {$setup_ran = true}
45
+
46
+ super_class_setup_ran = false
47
+ super_class = Class.new do
48
+ define_method :setup do
49
+ super_class_setup_ran = true
50
+ end
51
+ end
52
+ @context.inherit super_class
53
+
54
+ setup_ran = false
55
+ @context.setup {setup_ran = true}
46
56
  @context.specify("test") {true}
47
57
  @context.run(@formatter)
48
- assert $setup_ran
49
- @formatter.__verify
58
+ assert super_class_setup_ran
59
+ assert setup_ran
50
60
  end
51
61
 
52
- def test_teardwown
62
+ def test_setup__should_allow_method_definitions
53
63
  @formatter.should.receive(:add_context).with :any_args
54
64
  @formatter.should.receive(:spec_started).with "test"
55
65
  @formatter.should.receive(:spec_finished).with :any_args
56
- $teardwown_ran = false
57
- @context.teardown {$teardwown_ran = true}
66
+
67
+ $method_in_setup_called = false
68
+ @context.setup do
69
+ def method_in_setup
70
+ $method_in_setup_called = true
71
+ end
72
+ end
73
+
74
+ @context.specify("test") {method_in_setup}
75
+ @context.run(@formatter)
76
+
77
+ assert $method_in_setup_called
78
+ end
79
+
80
+ def test_teardown
81
+ @formatter.should.receive(:add_context).with :any_args
82
+ @formatter.should.receive(:spec_started).with "test"
83
+ @formatter.should.receive(:spec_finished).with :any_args
84
+
85
+ super_class_teardown_ran = false
86
+ super_class = Class.new do
87
+ define_method :teardown do
88
+ super_class_teardown_ran = true
89
+ end
90
+ end
91
+ @context.inherit super_class
92
+
93
+ teardown_ran = false
94
+ @context.teardown {teardown_ran = true}
58
95
  @context.specify("test") {true}
59
96
  @context.run(@formatter)
60
- assert $teardwown_ran
97
+ assert super_class_teardown_ran
98
+ assert teardown_ran
61
99
  @formatter.__verify
62
100
  end
101
+
102
+ def test_inherit__superclass_methods_should_be_accessible
103
+ @formatter.should.receive(:add_context).with :any_args
104
+ @formatter.should.receive(:spec_started).with "test"
105
+ @formatter.should.receive(:spec_finished).with :any_args
106
+
107
+ helper_method_ran = false
108
+ super_class = Class.new do
109
+ define_method :helper_method do
110
+ helper_method_ran = true
111
+ end
112
+ end
113
+ @context.inherit super_class
114
+
115
+ @context.specify("test") {helper_method}
116
+ @context.run(@formatter)
117
+ assert helper_method_ran
118
+ end
119
+
120
+ def test_inherit__class_methods_should_work
121
+ class_method_ran = false
122
+ super_class = Class.new
123
+ (class << super_class; self; end).class_eval do
124
+ define_method :class_method do
125
+ class_method_ran = true
126
+ end
127
+ end
128
+ @context.inherit super_class
129
+ @context.class_method
130
+ assert class_method_ran
131
+
132
+ assert_raise(NoMethodError) {@context.foobar}
133
+ end
134
+
135
+ def test_methods__should_include_inherited_class_methods
136
+ class_method_ran = false
137
+ super_class = Class.new
138
+ class << super_class
139
+ def super_class_class_method; end
140
+ end
141
+ @context.inherit super_class
142
+
143
+ assert @context.methods.include?("super_class_class_method")
144
+ end
145
+
146
+ def test_include
147
+ @formatter.should.receive(:add_context).with :any_args
148
+ @formatter.should.receive(:spec_started).with "test"
149
+ @formatter.should.receive(:spec_finished).with :any_args
150
+
151
+ mod1_method_called = false
152
+ mod1 = Module.new do
153
+ define_method :mod1_method do
154
+ mod1_method_called = true
155
+ end
156
+ end
157
+
158
+ mod2_method_called = false
159
+ mod2 = Module.new do
160
+ define_method :mod2_method do
161
+ mod2_method_called = true
162
+ end
163
+ end
164
+
165
+ @context.include mod1
166
+ @context.include mod2
167
+
168
+ @context.specify("test") do
169
+ mod1_method
170
+ mod2_method
171
+ end
172
+ @context.run(@formatter)
173
+ assert mod1_method_called
174
+ assert mod2_method_called
175
+ end
63
176
 
64
177
  def test_spec_count_1
65
178
  @context.specify("test") {}
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: rspec
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.13
7
- date: 2006-06-22 00:00:00 -05:00
8
- summary: RSpec-0.5.13 - BDD for Ruby http://rspec.rubyforge.org/
6
+ version: 0.5.14
7
+ date: 2006-07-14 00:00:00 -05:00
8
+ summary: RSpec-0.5.14 - BDD for Ruby http://rspec.rubyforge.org/
9
9
  require_paths:
10
10
  - lib
11
11
  email: rspec-devel@rubyforge.org
@@ -59,6 +59,7 @@ files:
59
59
  - lib/spec/rake/spectask.rb
60
60
  - lib/spec/runner/backtrace_tweaker.rb
61
61
  - lib/spec/runner/context.rb
62
+ - lib/spec/runner/context_eval.rb
62
63
  - lib/spec/runner/context_runner.rb
63
64
  - lib/spec/runner/execution_context.rb
64
65
  - lib/spec/runner/formatter.rb
@@ -84,6 +85,7 @@ files:
84
85
  - test/spec/api/helper/arbitrary_predicate_test.rb
85
86
  - test/spec/api/helper/containment_test.rb
86
87
  - test/spec/api/helper/diff_test.rb
88
+ - test/spec/api/helper/difference_test.rb
87
89
  - test/spec/api/helper/identity_test.rb
88
90
  - test/spec/api/helper/object_equality_test.rb
89
91
  - test/spec/api/helper/raising_test.rb
@@ -121,6 +123,7 @@ files:
121
123
  - examples/airport_spec.rb
122
124
  - examples/bdd_framework_spec.rb
123
125
  - examples/custom_formatter.rb
126
+ - examples/custom_method_spec.rb
124
127
  - examples/file_accessor.rb
125
128
  - examples/file_accessor_spec.rb
126
129
  - examples/io_processor.rb
@@ -129,6 +132,7 @@ files:
129
132
  - examples/stack.rb
130
133
  - examples/stack_spec.rb
131
134
  - examples/sugar_spec.rb
135
+ - examples/test_case_spec.rb
132
136
  test_files: []
133
137
 
134
138
  rdoc_options: