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,7 +1,6 @@
1
1
  ---
2
2
  title: Download
3
3
  inMenu: true
4
- ordering: 5
5
4
  ---
6
5
  h2. Download
7
6
 
@@ -1,9 +1,8 @@
1
1
  ---
2
2
  title: Examples
3
3
  inMenu: true
4
- ordering: 5
5
4
  ---
6
5
  h2. Examples
7
6
 
8
7
  Here is an example of an RSpec spec:
9
- {ruby_inline: {filename: ../examples/spec_framework_spec.rb}}
8
+ {ruby_inline: {filename: ../examples/stack_spec.rb}}
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  title: Overview
3
3
  inMenu: true
4
- ordering: 1
5
4
  ---
6
5
  h2. RSpec
7
6
 
@@ -0,0 +1,23 @@
1
+ index.page:
2
+ orderInfo: 1
3
+
4
+ why_rspec.page:
5
+ orderInfo: 2
6
+
7
+ examples.page:
8
+ orderInfo: 3
9
+
10
+ documentation:
11
+ title: Documentation
12
+ orderInfo: 4
13
+
14
+ download.page:
15
+ orderInfo: 5
16
+
17
+ tools:
18
+ title: Tools
19
+ orderInfo: 6
20
+
21
+ community.page:
22
+ orderInfo: 7
23
+
@@ -1,8 +1,143 @@
1
1
  ---
2
- title: Tools
2
+ title: Spec Runner
3
3
  inMenu: true
4
- ordering: 1
5
4
  ---
6
- h2. Tools
5
+ h2. Processing Specifications
7
6
 
8
- Look at my tools
7
+ The spec command processes specification files. The general form of the command is
8
+
9
+ <pre>
10
+ <code>
11
+ spec [options] (FILE|DIRECTORY)+
12
+ </code>
13
+ </pre>
14
+
15
+ Any number of files and/or directories can be provided, all ruby source files
16
+ that are found are loaded. Running spec on the previous example results in:
17
+
18
+ <pre>
19
+ <code>
20
+ ..................
21
+
22
+ Finished in 0.007523 seconds
23
+
24
+ 4 contexts, 18 specifications, 0 failures
25
+ </code>
26
+ </pre>
27
+
28
+ Very simple and to the point. Passing specifications are indicated by a '.',
29
+ failing ones by a 'F'. Note that failure indicates a violated expectation as
30
+ well as an unexpected exception being raised. Here's an example with a failing specification:
31
+
32
+ <pre>
33
+ <code>
34
+ F.
35
+
36
+ 1)
37
+ SpecFramework #<SpecFramework:0x3d73dc> should be adopted_quickly (Spec::Api::ExpectationNotMetError)
38
+ Context: Spec framework [./examples/spec_framework_spec.rb:13]
39
+ Specification: should be adopted quickly [./examples/spec_framework_spec.rb:19]
40
+ ./examples/spec_framework_spec.rb:21:in `should be adopted quickly'
41
+
42
+ Finished in 0.001565 seconds
43
+
44
+ 1 context, 2 specifications, 1 failure
45
+ </code>
46
+ </pre>
47
+
48
+ h3. -v, --verbose
49
+
50
+ Using this option provides more information:
51
+
52
+ <pre>
53
+ <code>
54
+ An empty stack

55
+ - should accept an item when sent push

56
+ - should complain when sent top

57
+ - should complain when sent pop


58
+
59
+ A stack with one item

60
+ - should accept an item when sent push

61
+ - should return top when sent top

62
+ - should not remove top when sent top

63
+ - should return top when sent pop

64
+ - should remove top when sent pop


65
+
66
+ An almost full stack (with one item less than capacity)

67
+ - should accept an item when sent push

68
+ - should return top when sent top

69
+ - should not remove top when sent top

70
+ - should return top when sent pop

71
+ - should remove top when sent pop


72
+
73
+ A full stack

74
+ - should complain on push

75
+ - should return top when sent top

76
+ - should not remove top when sent top

77
+ - should return top when sent pop

78
+ - should remove top when sent pop
79
+
80
+ Finished in 0.013635 seconds
81
+
82
+ 4 contexts, 18 specifications, 0 failures
83
+ </code>
84
+ </pre>
85
+
86
+ Similar, here is a failing specification when the verbose opton is used:
87
+
88
+ <pre>
89
+ <code>
90
+ Spec framework
91
+ - should be adopted quickly (FAILED - 1)
92
+ - should be intuitive
93
+
94
+
95
+ 1)
96
+ SpecFramework #<SpecFramework:0x3d7238> should be adopted_quickly (Spec::Api::ExpectationNotMetError)
97
+ Context: Spec framework [./examples/spec_framework_spec.rb:13]
98
+ Specification: should be adopted quickly [./examples/spec_framework_spec.rb:19]
99
+ ./examples/spec_framework_spec.rb:21:in `should be adopted quickly'
100
+
101
+ Finished in 0.002726 seconds
102
+
103
+ 1 context, 2 specifications, 1 failure
104
+ </code>
105
+ </pre>
106
+
107
+ The spec command does double duty as documentation generation from a set of
108
+ specifications as well as running them against your code.
109
+
110
+ h3.-d, --doc
111
+
112
+ Process the specifications in documentation generation mode. This will produce
113
+ an rdoc input file. For example here is the result of running spec -d on the
114
+ previous example:
115
+
116
+ <pre>
117
+ <code>
118
+ # An empty stack

119
+ # * should accept an item when sent push

120
+ # * should complain when sent top

121
+ # * should complain when sent pop

122
+ # A stack with one item

123
+ # * should accept an item when sent push

124
+ # * should return top when sent top

125
+ # * should not remove top when sent top

126
+ # * should return top when sent pop

127
+ # * should remove top when sent pop

128
+ # An almost full stack (with one item less than capacity)

129
+ # * should accept an item when sent push

130
+ # * should return top when sent top

131
+ # * should not remove top when sent top

132
+ # * should return top when sent pop

133
+ # * should remove top when sent pop

134
+ # A full stack

135
+ # * should complain on push

136
+ # * should return top when sent top

137
+ # * should not remove top when sent top

138
+ # * should return top when sent pop

139
+ # * should remove top when sent pop
140
+ </code>
141
+ </pre>
142
+
143
+ Rdoc renders this as "this":rdoc-output/index.html.
@@ -0,0 +1,12 @@
1
+ index.page:
2
+ orderInfo: 10
3
+
4
+ test2rspec.page:
5
+ orderInfo: 11
6
+
7
+ rake.page:
8
+ orderInfo: 12
9
+
10
+ rails.page:
11
+ orderInfo: 13
12
+
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  title: Rails Integration
3
3
  inMenu: true
4
- ordering: 5
5
4
  ---
6
5
  h2. Rails Integration
7
6
 
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  title: Rake Integration
3
3
  inMenu: true
4
- ordering: 5
5
4
  ---
6
5
  h2. Rake Integration
7
6
 
@@ -1,8 +1,15 @@
1
1
  ---
2
- title: Test::Unit migration
2
+ title: Test::Unit Migration
3
3
  inMenu: true
4
- ordering: 5
5
4
  ---
6
5
  h2. Test::Unit migration
7
6
 
8
- lalalala
7
+ rSpec provides a tool for converting Test::Unit files into specifications. Anything that cannot be converted is left in it's original form. The command line is:
8
+
9
+ <pre>
10
+ <code>
11
+ test2rspec SRC [DEST]
12
+ </code>
13
+ </pre>
14
+
15
+ If DEST is not supplied, output is sent to STDOUT.
@@ -1,7 +1,6 @@
1
1
  ---
2
2
  title: Why RSpec
3
3
  inMenu: true
4
- ordering: 2
5
4
  ---
6
5
  h2. Why RSpec
7
6
 
@@ -10,20 +10,30 @@ class Airport
10
10
  end
11
11
  end
12
12
 
13
- context "Airport at home" do
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
+
23
+ topic "Airport at home" do
14
24
  setup do
15
25
  @airport = Airport.new
16
26
  end
17
27
 
18
- specify "should always work" do
28
+ fact "should always work" do
19
29
  @airport.should.be.working
20
30
  end
21
31
 
22
- specify "should not need cables" do
32
+ must "not need cables" do
23
33
  @airport.should.not.need :cables
24
34
  end
25
35
 
26
- specify "should not need electricity" do
36
+ must "not need electricity" do
27
37
  # This will fail...
28
38
  @airport.should.not.need :electricity
29
39
  end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/stack"
2
+
3
+ context "An empty stack" do
4
+
5
+ setup do
6
+ @stack = Stack.new
7
+ end
8
+
9
+ specify "should accept an item when sent push" do
10
+ lambda { @stack.push Object.new }.should.not.raise
11
+ end
12
+
13
+ specify "should complain when sent top" do
14
+ lambda { @stack.top }.should.raise StackUnderflowError
15
+ end
16
+
17
+ specify "should complain when sent pop" do
18
+ lambda { @stack.pop }.should.raise StackUnderflowError
19
+ end
20
+
21
+ end
@@ -1,3 +1,5 @@
1
+ require File.dirname(__FILE__) + "/stack"
2
+
1
3
  context "An empty stack" do
2
4
 
3
5
  setup do
@@ -18,7 +20,7 @@ context "An empty stack" do
18
20
 
19
21
  end
20
22
 
21
- context "A stack with one item" do
23
+ context "A stack with one item" do
22
24
  setup do
23
25
  @stack = Stack.new
24
26
  @stack.push 3
@@ -77,6 +79,7 @@ context "An almost full stack (with one item less than capacity)" do
77
79
  end
78
80
 
79
81
  end
82
+
80
83
  context "A full stack" do
81
84
 
82
85
  setup do
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.push File.dirname(__FILE__) + '/../lib'
2
2
 
3
+ require 'spec/version'
3
4
  require 'spec/api'
4
5
  require 'spec/runner'
5
- require 'spec/runner/kernel_ext'
6
+ require 'spec/runner/kernel_ext'
@@ -14,16 +14,17 @@ module Spec
14
14
  HaveHelper.new(@target, expected_number)
15
15
  end
16
16
 
17
- def satisfy
18
- fail_with_message "Supplied expectation was not satisfied" if (!yield @target)
17
+ def satisfy(&block)
18
+ return if block.call(@target)
19
+ fail_with_message "Supplied expectation was not satisfied"
19
20
  end
20
21
 
21
22
  def equal(expected)
22
23
  fail_with_message(default_message("should equal", expected)) unless (@target == expected)
23
24
  end
24
25
 
25
- def be(expected = :no_arg)
26
- return self if (expected == :no_arg)
26
+ def be(expected = :___no_arg)
27
+ return self if (expected == :___no_arg)
27
28
  return if (expected == false and @target.nil?)
28
29
  return if (expected == true and (!@target.nil?) and (@target != false))
29
30
  fail_with_message(default_message("should be", expected)) unless (@target.equal?(expected))
@@ -51,6 +51,7 @@ module Spec
51
51
  rescue exception
52
52
  fail_with_message(default_message("should not raise", exception.inspect))
53
53
  rescue
54
+ true
54
55
  end
55
56
  end
56
57
 
@@ -62,6 +63,7 @@ module Spec
62
63
  end
63
64
  fail_with_message(default_message("should not throw", symbol.inspect))
64
65
  rescue NameError
66
+ true
65
67
  end
66
68
  end
67
69
 
@@ -81,8 +81,9 @@ module Spec
81
81
  end
82
82
 
83
83
  def constraints_match?(args)
84
+ return true if @expected_params.length == 1 and @expected_params[0] == :any_args
84
85
  return false if args.length != @expected_params.length
85
- for i in 0...@expected_params.length
86
+ @expected_params.each_index do |i|
86
87
  next if @expected_params[i] == :anything
87
88
  next if @expected_params[i] == :numeric and args[i].is_a?Numeric
88
89
  next if @expected_params[i] == :boolean and args[i].is_a?TrueClass or args[i].is_a?FalseClass
@@ -144,10 +145,6 @@ module Spec
144
145
  return result
145
146
  end
146
147
 
147
- unless @expected_params.nil? or @expected_params == args or constraints_match?(args)
148
- Kernel::raise Spec::Api::MockExpectationError,
149
- "#{@sym}: Parameter mismatch: Expected <#{@expected_params}>, got <#{args}>"
150
- end
151
148
  args << block unless block.nil?
152
149
  @received_count += 1
153
150
 
@@ -162,8 +159,8 @@ module Spec
162
159
  end
163
160
 
164
161
  def with(*args)
165
- if args == [:anything] then @expected_params = nil
166
- elsif args == [:nothing] then @expected_params = []
162
+ if args == [:any_args] then @expected_params = nil
163
+ elsif args == [:no_args] then @expected_params = []
167
164
  else @expected_params = args
168
165
  end
169
166
 
@@ -3,14 +3,13 @@ module Spec
3
3
  class BacktraceTweaker
4
4
  def tweak_backtrace error, spec_name
5
5
  return if error.backtrace.nil?
6
- tweaked_backtrace = []
7
- error.backtrace.each do |line|
6
+ error.backtrace.collect! do |line|
8
7
  line = line.split(':in')[0] + ":in `#{spec_name}'" if line.include?('__instance_exec')
9
8
  line = nil if line.include? '/lib/spec/api/helper/should_base.rb'
10
9
  line = nil if line.include? '/lib/spec/api/helper/should_negator.rb' unless line.nil?
11
- tweaked_backtrace.push line unless line.nil?
10
+ line
12
11
  end
13
- error.set_backtrace tweaked_backtrace
12
+ error.backtrace.compact!
14
13
  end
15
14
  end
16
15
  end
@@ -10,6 +10,10 @@ module Spec
10
10
  @spec.add_mock(mock)
11
11
  mock
12
12
  end
13
+
14
+ def violated(message="")
15
+ raise Spec::Api::ExpectationNotMetError.new(message)
16
+ end
13
17
  end
14
18
  end
15
19
  end