rspec 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/CHANGES +9 -1
  2. data/README +1 -0
  3. data/Rakefile +14 -6
  4. data/doc/README +1 -1
  5. data/doc/reference/rspec reference.page +0 -0
  6. data/doc/src/community.page +0 -1
  7. data/doc/src/default.template +1 -3
  8. data/doc/src/documentation/api.page +36 -35
  9. data/doc/src/documentation/index.page +9 -4
  10. data/doc/src/documentation/meta.info +22 -0
  11. data/doc/src/documentation/mocks.page +68 -32
  12. data/doc/src/download.page +0 -1
  13. data/doc/src/examples.page +1 -2
  14. data/doc/src/index.page +0 -1
  15. data/doc/src/meta.info +23 -0
  16. data/doc/src/tools/index.page +139 -4
  17. data/doc/src/tools/meta.info +12 -0
  18. data/doc/src/tools/rails.page +0 -1
  19. data/doc/src/tools/rake.page +0 -1
  20. data/doc/src/tools/test2rspec.page +10 -3
  21. data/doc/src/why_rspec.page +0 -1
  22. data/examples/airport_spec.rb +14 -4
  23. data/examples/empty_stack_spec.rb +21 -0
  24. data/examples/stack_spec.rb +4 -1
  25. data/lib/spec.rb +2 -1
  26. data/lib/spec/api/helper/should_helper.rb +5 -4
  27. data/lib/spec/api/helper/should_negator.rb +2 -0
  28. data/lib/spec/api/mock.rb +4 -7
  29. data/lib/spec/runner/backtrace_tweaker.rb +3 -4
  30. data/lib/spec/runner/execution_context.rb +4 -0
  31. data/lib/spec/runner/kernel_ext.rb +1 -2
  32. data/lib/spec/runner/option_parser.rb +12 -7
  33. data/lib/spec/version.rb +10 -7
  34. data/test/spec/api/helper/raising_test.rb +12 -0
  35. data/test/spec/api/helper/should_satisfy_test.rb +8 -6
  36. data/test/spec/api/mock_arg_constraints_test.rb +1 -10
  37. data/test/spec/api/mock_test.rb +71 -2
  38. data/test/spec/runner/context_runner_test.rb +23 -0
  39. data/test/spec/runner/context_test.rb +41 -0
  40. data/test/spec/runner/execution_context_test.rb +7 -0
  41. data/test/spec/runner/kernel_ext_test.rb +14 -0
  42. data/test/spec/runner/option_parser_test.rb +17 -10
  43. metadata +8 -8
  44. data/doc/src/documentation/specs.page +0 -20
  45. data/doc/src/tools/rcov.page +0 -8
  46. data/doc/src/tools/spec_runner.page +0 -8
  47. data/doc/src/tools/specdoc.page +0 -8
@@ -1,6 +1,5 @@
1
1
  module Kernel
2
2
  def context(name, &block)
3
- Spec::Runner::Context.new(name, &block) unless $generating_docs
4
- Spec::Runner::DocumentationContext.new(name, &block) if $generating_docs
3
+ Spec::Runner::Context.new(name, &block)
5
4
  end
6
5
  end
@@ -4,11 +4,11 @@ module Spec
4
4
  module Runner
5
5
  class OptionParser
6
6
 
7
- def self.parse(args, standalone=false, err=$stderr)
7
+ def self.parse(args, standalone=false, err=$stderr, out=$stdout)
8
8
  options = OpenStruct.new
9
- options.out = $stdout
10
- options.verbose = false;
11
- options.doc = false;
9
+ options.out = out
10
+ options.verbose = false
11
+ options.doc = false
12
12
 
13
13
  opts = ::OptionParser.new do |opts|
14
14
  opts.banner = "Usage: spec [options] (FILE|DIRECTORY)+"
@@ -19,17 +19,22 @@ module Spec
19
19
  exit if outfile.nil?
20
20
  end
21
21
 
22
- opts.on("-v", "--verbose") do
22
+ opts.on("-v", "--verbose", "Verbose output") do
23
23
  options.verbose = true
24
24
  end
25
25
 
26
- opts.on("-d", "--doc", "Generate documentation") do
26
+ opts.on("-d", "--doc", "Output specdoc only") do
27
27
  options.doc = true
28
28
  end
29
29
 
30
+ opts.on("--version", "Show version") do
31
+ out.puts ::Spec::VERSION::DESCRIPTION
32
+ exit if out == $stdout
33
+ end
34
+
30
35
  opts.on_tail("-h", "--help", "Show this message") do
31
36
  err.puts opts
32
- exit if err == $stderr
37
+ exit if out == $stdout
33
38
  end
34
39
 
35
40
  end
@@ -1,13 +1,16 @@
1
1
  module Spec
2
2
  module VERSION
3
- MAJOR = 0
4
- MINOR = 5
5
- TINY = 1
3
+ unless defined? MAJOR
4
+ MAJOR = 0
5
+ MINOR = 5
6
+ TINY = 2
6
7
 
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
9
 
9
- NAME = "RSCM"
10
- FULLNAME = "RSpec"
11
- URL = "http://rspec.rubyforge.org/"
10
+ NAME = "RSpec"
11
+ URL = "http://rspec.rubyforge.org/"
12
+
13
+ DESCRIPTION = "#{NAME}-#{STRING} - BDD for Ruby\n#{URL}"
14
+ end
12
15
  end
13
16
  end
@@ -44,6 +44,18 @@ module Spec
44
44
  proc { ''.to_s }.should.not.raise NoMethodError
45
45
  end
46
46
  end
47
+
48
+ def test_should_not_raise_without_exception_should_pass_when_no_exception_is_raised
49
+ assert_nothing_raised do
50
+ proc { ''.to_s }.should.not.raise
51
+ end
52
+ end
53
+
54
+ def TODOtest_should_understand_raised_with_message_matching
55
+ lambda do
56
+ raise 'Hello'
57
+ end.should.raise(StandardError).with.message.matching /ello/
58
+ end
47
59
  end
48
60
  end
49
61
  end
@@ -1,5 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../../../test_helper'
2
2
 
3
+
4
+
3
5
  module Spec
4
6
  module Api
5
7
  module Helper
@@ -7,27 +9,27 @@ module Spec
7
9
 
8
10
  def test_should_raise_exception_when_block_yields_false
9
11
  assert_raise(ExpectationNotMetError) do
10
- 5.should.satisfy { false }
12
+ 5.should.satisfy {|target| false }
11
13
  end
12
14
  end
13
15
 
14
16
  def test_should_not_raise_exception_when_block_yields_true
15
17
  assert_nothing_raised do
16
- 5.should.satisfy { true }
18
+ 5.should.satisfy {|target| true }
17
19
  end
18
20
  end
19
21
 
20
22
  # should.not.satisfy
21
23
 
22
- def test_should_raise_exception_when_block_yields_false
24
+ def test_should_raise_exception_when_block_yields_false_again
23
25
  assert_raise(ExpectationNotMetError) do
24
- 5.should.not.satisfy { true }
26
+ 5.should.not.satisfy {|target| true }
25
27
  end
26
28
  end
27
29
 
28
- def test_should_not_raise_exception_when_block_yields_true
30
+ def test_should_not_raise_exception_when_block_yields_true_again
29
31
  assert_nothing_raised do
30
- 5.should.not.satisfy { false }
32
+ 5.should.not.satisfy {|target| false }
31
33
  end
32
34
  end
33
35
 
@@ -8,16 +8,7 @@ module Spec
8
8
  @mock = Mock.new("test mock")
9
9
  end
10
10
 
11
- def test_should_handle_anything
12
- @mock.should.receive(:random_call).at.least(:once).with(:anything)
13
- @mock.random_call()
14
- @mock.random_call(1)
15
- @mock.random_call("a", 2)
16
- @mock.random_call([], {}, "joe", 7)
17
- @mock.__verify
18
- end
19
-
20
- def test_should_handle_anything_in_multi_args
11
+ def test_should_handle_any_arg
21
12
  @mock.should.receive(:random_call).with("a", :anything, "c")
22
13
  @mock.random_call("a", "whatever", "c")
23
14
  @mock.__verify
@@ -92,14 +92,14 @@ module Spec
92
92
  end
93
93
 
94
94
  def test_two_return_values
95
- @mock.should.receive(:multi_call).twice.with(:nothing).and.return([1, 2])
95
+ @mock.should.receive(:multi_call).twice.with(:no_args).and.return([1, 2])
96
96
  assert_equal(1, @mock.multi_call)
97
97
  assert_equal(2, @mock.multi_call)
98
98
  @mock.__verify
99
99
  end
100
100
 
101
101
  def test_repeating_final_return_value
102
- @mock.should.receive(:multi_call).at.least(:once).with(:nothing).and.return([1, 2])
102
+ @mock.should.receive(:multi_call).at.least(:once).with(:no_args).and.return([1, 2])
103
103
  assert_equal(1, @mock.multi_call)
104
104
  assert_equal(2, @mock.multi_call)
105
105
  assert_equal(2, @mock.multi_call)
@@ -221,6 +221,50 @@ module Spec
221
221
  @mock.random_call
222
222
  @mock.__verify
223
223
  end
224
+
225
+ def test_should_raise_if_exactly_3_times_method_is_not_called
226
+ @mock.should.receive(:random_call).exactly(3).times
227
+ assert_raise(MockExpectationError) do
228
+ @mock.__verify
229
+ end
230
+ end
231
+
232
+ def test_should_raise_if_exactly_3_times_method_is_called_once
233
+ @mock.should.receive(:random_call).exactly(3).times
234
+ @mock.random_call
235
+ assert_raise(MockExpectationError) do
236
+ @mock.__verify
237
+ end
238
+ end
239
+
240
+ def test_should_raise_if_exactly_3_times_method_is_called_twice
241
+ @mock.should.receive(:random_call).exactly(3).times
242
+ @mock.random_call
243
+ @mock.random_call
244
+ assert_raise(MockExpectationError) do
245
+ @mock.__verify
246
+ end
247
+ end
248
+
249
+ def test_should_not_raise_if_exactly_3_times_method_is_called_3_times
250
+ @mock.should.receive(:random_call).exactly(3).times
251
+ @mock.random_call
252
+ @mock.random_call
253
+ @mock.random_call
254
+ assert_nothing_raised do
255
+ @mock.__verify
256
+ end
257
+ end
258
+
259
+ def test_should_raise_if_exactly_3_times_method_is_called_4_times
260
+ @mock.should.receive(:random_call).exactly(3).times
261
+ @mock.random_call
262
+ @mock.random_call
263
+ @mock.random_call
264
+ assert_nothing_raised do
265
+ @mock.random_call
266
+ end
267
+ end
224
268
 
225
269
  def test_raising
226
270
  @mock.should.receive(:random_call).and.raise(RuntimeError)
@@ -235,7 +279,32 @@ module Spec
235
279
  @mock.random_call
236
280
  end
237
281
  end
282
+
283
+ def TODO_test_should_use_past_tense
284
+ @mock.should.have.received(:hello)
285
+ end
286
+
287
+ def TODO_test_should_sent
288
+ cut.should.have.sent(:hello)
289
+ cut.should.have.sent(:hello).to(@mock)
290
+ end
238
291
 
292
+ def test_should_ignore_args_on_any_args
293
+ @mock.should.receive(:random_call).at.least(:once).with(:any_args)
294
+ @mock.random_call()
295
+ @mock.random_call(1)
296
+ @mock.random_call("a", 2)
297
+ @mock.random_call([], {}, "joe", 7)
298
+ @mock.__verify
299
+ end
300
+
301
+ def test_should_throw_on_no_args_if_any_args_received
302
+ @mock.should.receive(:random_call).with(:no_args)
303
+ assert_raise(MockExpectationError) do
304
+ @mock.random_call(1)
305
+ end
306
+ end
307
+
239
308
  end
240
309
  end
241
310
  end
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../../test_helper'
2
2
  module Spec
3
3
  module Runner
4
4
  class ContextRunnerTest < Test::Unit::TestCase
5
+
5
6
  def test_should_call_run_doc_on_context
6
7
  context1 = Api::Mock.new "context1"
7
8
  context2 = Api::Mock.new "context2"
@@ -14,6 +15,28 @@ module Spec
14
15
  context1.__verify
15
16
  context2.__verify
16
17
  end
18
+
19
+ def test_should_call_run_on_context
20
+ context1 = Api::Mock.new "context1"
21
+ context2 = Api::Mock.new "context2"
22
+ context1.should.receive(:run)
23
+ context2.should.receive(:run)
24
+ runner = ContextRunner.new [], false, StringIO.new
25
+ runner.add_context context1
26
+ runner.add_context context2
27
+ runner.run
28
+ context1.__verify
29
+ context2.__verify
30
+ end
31
+
32
+
33
+ def test_should_call_run_for_standalone
34
+ context1 = Api::Mock.new "context1"
35
+ context1.should.receive(:run)
36
+ runner = ContextRunner.standalone context1
37
+ context1.__verify
38
+ end
39
+
17
40
  end
18
41
  end
19
42
  end
@@ -20,6 +20,47 @@ module Spec
20
20
  @context.run_docs(@listener)
21
21
  @listener.__verify
22
22
  end
23
+
24
+ def test_spec
25
+ @listener.should.receive(:add_context).with :any_args
26
+ @listener.should.receive(:add_spec).with "test", :anything, :anything
27
+ $spec_ran = false
28
+ @context.specify("test") {$spec_ran = true}
29
+ @context.run(@listener)
30
+ assert $spec_ran
31
+ @listener.__verify
32
+ end
33
+
34
+ def test_spec_doc
35
+ @listener.should.receive(:add_context).with :any_args
36
+ @listener.should.receive(:add_spec).with "test"
37
+ @context.specify("test") {}
38
+ @context.run_docs(@listener)
39
+ assert $spec_ran
40
+ @listener.__verify
41
+ end
42
+
43
+ def test_setup
44
+ @listener.should.receive(:add_context).with :any_args
45
+ @listener.should.receive(:add_spec).with :any_args
46
+ $setup_ran = false
47
+ @context.setup {$setup_ran = true}
48
+ @context.specify("test") {true}
49
+ @context.run(@listener)
50
+ assert $setup_ran
51
+ @listener.__verify
52
+ end
53
+
54
+ def test_teardwown
55
+ @listener.should.receive(:add_context).with :any_args
56
+ @listener.should.receive(:add_spec).with :any_args
57
+ $teardwown_ran = false
58
+ @context.teardown {$teardwown_ran = true}
59
+ @context.specify("test") {true}
60
+ @context.run(@listener)
61
+ assert $teardwown_ran
62
+ @listener.__verify
63
+ end
23
64
 
24
65
  end
25
66
  end
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../../test_helper'
2
+
2
3
  module Spec
3
4
  module Runner
4
5
  class ExecutionContextTest < Test::Unit::TestCase
@@ -8,6 +9,12 @@ module Spec
8
9
  ec = ExecutionContext.new spec
9
10
  mock = ec.mock("a mock")
10
11
  end
12
+
13
+ def test_violated
14
+ assert_raise(Spec::Api::ExpectationNotMetError) do
15
+ ExecutionContext.new(nil).violated
16
+ end
17
+ end
11
18
  end
12
19
  end
13
20
  end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Spec
4
+ module Runner
5
+ class KernelExtTest < Test::Unit::TestCase
6
+ def test_create_context
7
+ assert_nothing_raised do
8
+ @cxt = context("") {}
9
+ end
10
+ assert @cxt.instance_of? Spec::Runner::Context
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,11 +6,18 @@ module Spec
6
6
  class OptionParserTest < Test::Unit::TestCase
7
7
 
8
8
  def setup
9
+ @out = StringIO.new
9
10
  @err = StringIO.new
10
11
  end
11
12
 
13
+ def test_should_print_version
14
+ options = OptionParser.parse(["--version"], false, @err, @out)
15
+ @out.rewind
16
+ assert_match(/RSpec-\d+\.\d+\.\d+ - BDD for Ruby\nhttp:\/\/rspec.rubyforge.org\/\n/n, @out.read)
17
+ end
18
+
12
19
  def test_verbose_should_be_true_by_default
13
- options = OptionParser.parse([], false, @err)
20
+ options = OptionParser.parse([], false, @err, @out)
14
21
  assert(!options.verbose)
15
22
  end
16
23
 
@@ -20,37 +27,37 @@ module Spec
20
27
  end
21
28
 
22
29
  def test_verbose_should_be_settable_with_v
23
- options = OptionParser.parse(["-v"], false, @err)
30
+ options = OptionParser.parse(["-v"], false, @err, @out)
24
31
  assert(options.verbose)
25
32
  end
26
33
 
27
34
  def test_verbose_should_be_settable_with_verbose
28
- options = OptionParser.parse(["--verbose"], false, @err)
35
+ options = OptionParser.parse(["--verbose"], false, @err, @out)
29
36
  assert(options.verbose)
30
37
  end
31
38
 
32
39
  def test_doc_should_be_false_by_default
33
- options = OptionParser.parse([], false, @err)
40
+ options = OptionParser.parse([], false, @err, @out)
34
41
  assert(!options.doc)
35
42
  end
36
43
 
37
44
  def test_doc_should_be_settable_with_d
38
- options = OptionParser.parse(["-d"], false, @err)
45
+ options = OptionParser.parse(["-d"], false, @err, @out)
39
46
  assert(options.doc)
40
47
  end
41
48
 
42
49
  def test_out_should_be_settable_with_o
43
- options = OptionParser.parse(["-o","test.txt"], false, @err)
50
+ options = OptionParser.parse(["-o","test.txt"], false, @err, @out)
44
51
  assert_equal("test.txt", options.out)
45
52
  end
46
53
 
47
54
  def test_out_should_be_settable_with_of
48
- options = OptionParser.parse(["--of","test.txt"], false, @err)
55
+ options = OptionParser.parse(["--of","test.txt"], false, @err, @out)
49
56
  assert_equal("test.txt", options.out)
50
57
  end
51
-
52
- def test_should_print_usage_if_no_dir_specified
53
- options = OptionParser.parse([], false, @err)
58
+
59
+ def test_should_print_usage_to_err_if_no_dir_specified
60
+ options = OptionParser.parse([], false, @err, @out)
54
61
  assert_match(/Usage: spec/, @err.string)
55
62
  end
56
63
  end
metadata CHANGED
@@ -3,8 +3,8 @@ 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.1
7
- date: 2006-04-08 00:00:00 -05:00
6
+ version: 0.5.2
7
+ date: 2006-04-09 00:00:00 -05:00
8
8
  summary: Behaviour Specification Framework for Ruby
9
9
  require_paths:
10
10
  - lib
@@ -30,6 +30,7 @@ authors:
30
30
  files:
31
31
  - CHANGES
32
32
  - Rakefile
33
+ - README
33
34
  - lib/spec.rb
34
35
  - lib/spec/api.rb
35
36
  - lib/spec/runner.rb
@@ -80,6 +81,7 @@ files:
80
81
  - test/spec/runner/context_runner_test.rb
81
82
  - test/spec/runner/context_test.rb
82
83
  - test/spec/runner/execution_context_test.rb
84
+ - test/spec/runner/kernel_ext_test.rb
83
85
  - test/spec/runner/option_parser_test.rb
84
86
  - test/spec/runner/rdoc_formatter_test.rb
85
87
  - test/spec/runner/simple_text_reporter_test.rb
@@ -89,17 +91,16 @@ files:
89
91
  - test/spec/tool/test_unit_api_test.rb
90
92
  - test/spec/tool/test_unit_translator_test.rb
91
93
  - examples/airport_spec.rb
94
+ - examples/empty_stack_spec.rb
92
95
  - examples/mocking_spec.rb
93
96
  - examples/spec_framework_spec.rb
94
97
  - examples/stack.rb
95
98
  - examples/stack_spec.rb
96
99
  - doc/config.yaml
97
- - doc/output
98
100
  - doc/plugin
99
101
  - doc/README
100
102
  - doc/reference
101
103
  - doc/src
102
- - doc/output/rdoc
103
104
  - doc/plugin/syntax.rb
104
105
  - doc/reference/rspec reference.page
105
106
  - doc/src/community.page
@@ -110,20 +111,19 @@ files:
110
111
  - doc/src/examples.page
111
112
  - doc/src/images
112
113
  - doc/src/index.page
114
+ - doc/src/meta.info
113
115
  - doc/src/tools
114
116
  - doc/src/ul.gif
115
117
  - doc/src/why_rspec.page
116
118
  - doc/src/documentation/api.page
117
119
  - doc/src/documentation/index.page
120
+ - doc/src/documentation/meta.info
118
121
  - doc/src/documentation/mocks.page
119
- - doc/src/documentation/specs.page
120
122
  - doc/src/images/ul.gif
121
123
  - doc/src/tools/index.page
124
+ - doc/src/tools/meta.info
122
125
  - doc/src/tools/rails.page
123
126
  - doc/src/tools/rake.page
124
- - doc/src/tools/rcov.page
125
- - doc/src/tools/spec_runner.page
126
- - doc/src/tools/specdoc.page
127
127
  - doc/src/tools/test2rspec.page
128
128
  test_files: []
129
129