rspec 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +90 -1
- data/EXAMPLES.rd +28 -6
- data/MIT-LICENSE +20 -0
- data/README +18 -12
- data/Rakefile +60 -54
- data/examples/custom_formatter.rb +4 -4
- data/examples/helper_method_example.rb +11 -0
- data/examples/mocking_example.rb +19 -2
- data/examples/partial_mock_example.rb +28 -0
- data/examples/stack_spec.rb +8 -8
- data/examples/stubbing_example.rb +50 -9
- data/examples/test_case_spec.rb +6 -6
- data/lib/spec.rb +1 -2
- data/lib/spec/callback.rb +0 -0
- data/lib/spec/expectations.rb +3 -6
- data/lib/spec/expectations/diff.rb +23 -47
- data/lib/spec/expectations/differs/default.rb +62 -0
- data/lib/spec/expectations/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/expectations/extensions.rb +4 -0
- data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +14 -0
- data/lib/spec/expectations/extensions/numeric.rb +5 -0
- data/lib/spec/expectations/{expectations.rb → extensions/object.rb} +3 -6
- data/lib/spec/expectations/extensions/symbol.rb +5 -0
- data/lib/spec/expectations/should.rb +4 -0
- data/lib/spec/expectations/should/base.rb +42 -0
- data/lib/spec/expectations/should/have.rb +79 -0
- data/lib/spec/expectations/should/not.rb +72 -0
- data/lib/spec/expectations/should/should.rb +83 -0
- data/lib/spec/expectations/sugar.rb +6 -25
- data/lib/spec/mocks.rb +5 -1
- data/lib/spec/mocks/argument_expectation.rb +15 -1
- data/lib/spec/mocks/error_generator.rb +72 -0
- data/lib/spec/mocks/{exceptions.rb → errors.rb} +0 -0
- data/lib/spec/mocks/extensions/object.rb +3 -0
- data/lib/spec/mocks/message_expectation.rb +80 -73
- data/lib/spec/mocks/mock.rb +4 -69
- data/lib/spec/mocks/mock_handler.rb +158 -0
- data/lib/spec/mocks/mock_methods.rb +44 -0
- data/lib/spec/mocks/order_group.rb +10 -2
- data/lib/spec/rake/spectask.rb +20 -18
- data/lib/spec/rake/{rcov_verify.rb → verify_rcov.rb} +2 -2
- data/lib/spec/runner.rb +3 -1
- data/lib/spec/runner/backtrace_tweaker.rb +2 -1
- data/lib/spec/runner/context.rb +10 -16
- data/lib/spec/runner/context_eval.rb +40 -40
- data/lib/spec/runner/execution_context.rb +1 -12
- data/lib/spec/runner/{kernel_ext.rb → extensions/kernel.rb} +2 -2
- data/lib/spec/runner/{instance_exec.rb → extensions/object.rb} +0 -0
- data/lib/spec/runner/formatter/base_text_formatter.rb +25 -18
- data/lib/spec/runner/formatter/html_formatter.rb +81 -101
- data/lib/spec/runner/formatter/progress_bar_formatter.rb +9 -9
- data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
- data/lib/spec/runner/formatter/specdoc_formatter.rb +7 -6
- data/lib/spec/runner/option_parser.rb +41 -5
- data/lib/spec/runner/reporter.rb +3 -15
- data/lib/spec/runner/spec_should_raise_handler.rb +74 -0
- data/lib/spec/runner/specification.rb +33 -14
- data/lib/spec/version.rb +6 -3
- data/vendor/watir/README.txt +1 -1
- metadata +34 -68
- data/bin/test2spec +0 -112
- data/examples/helper_method_spec.rb +0 -12
- data/lib/spec/expectations/have_helper.rb +0 -41
- data/lib/spec/expectations/helper.rb +0 -4
- data/lib/spec/expectations/should_base.rb +0 -52
- data/lib/spec/expectations/should_helper.rb +0 -93
- data/lib/spec/expectations/should_negator.rb +0 -71
- data/lib/spec/test_to_spec/ruby2ruby.rb +0 -492
- data/lib/spec/test_to_spec/sexp_transformer.rb +0 -196
- data/lib/spec/test_to_spec/test_case_ext.rb +0 -22
- data/lib/spec/test_to_spec/translation_test_runner.rb +0 -147
- data/test/spec/expectations/arbitrary_operator_test.rb +0 -55
- data/test/spec/expectations/arbitrary_predicate_test.rb +0 -163
- data/test/spec/expectations/containment_test.rb +0 -129
- data/test/spec/expectations/diff_test.rb +0 -62
- data/test/spec/expectations/identity_test.rb +0 -75
- data/test/spec/expectations/object_equality_test.rb +0 -65
- data/test/spec/expectations/raising_test.rb +0 -106
- data/test/spec/expectations/regex_matching_test.rb +0 -36
- data/test/spec/expectations/should_have_test.rb +0 -169
- data/test/spec/expectations/should_satisfy_test.rb +0 -37
- data/test/spec/expectations/sugar_test.rb +0 -93
- data/test/spec/expectations/supported_symbols_test.rb +0 -33
- data/test/spec/expectations/throwing_test.rb +0 -55
- data/test/spec/expectations/true_false_special_case_test.rb +0 -85
- data/test/spec/expectations/typing_test.rb +0 -108
- data/test/spec/mocks/mock_arg_constraints_test.rb +0 -113
- data/test/spec/mocks/mock_counts_test.rb +0 -431
- data/test/spec/mocks/mock_ordering_test.rb +0 -109
- data/test/spec/mocks/mock_test.rb +0 -220
- data/test/spec/mocks/null_object_test.rb +0 -37
- data/test/spec/runner/backtrace_tweaker_test.rb +0 -90
- data/test/spec/runner/context_matching_test.rb +0 -35
- data/test/spec/runner/context_runner_test.rb +0 -62
- data/test/spec/runner/context_test.rb +0 -191
- data/test/spec/runner/execution_context_test.rb +0 -45
- data/test/spec/runner/formatter/failure_dump_test.rb +0 -94
- data/test/spec/runner/formatter/html_formatter_test.rb +0 -48
- data/test/spec/runner/formatter/progress_bar_formatter_test.rb +0 -56
- data/test/spec/runner/formatter/rdoc_formatter_test.rb +0 -51
- data/test/spec/runner/formatter/specdoc_formatter_test.rb +0 -57
- data/test/spec/runner/kernel_ext_test.rb +0 -13
- data/test/spec/runner/option_parser_test.rb +0 -141
- data/test/spec/runner/reporter_test.rb +0 -128
- data/test/spec/runner/spec_matcher_test.rb +0 -47
- data/test/spec/runner/specification_test.rb +0 -121
- data/test/spec/test_to_spec/ruby_to_ruby_test.rb +0 -79
- data/test/spec/test_to_spec/sexp_transformer_assertion_test.rb +0 -207
- data/test/spec/test_to_spec/sexp_transformer_test.rb +0 -303
- data/test/spec/test_to_spec/test_case_ext_test.rb +0 -25
- data/test/spec/test_to_spec/testfiles/test_unit_api_spec.rb +0 -75
- data/test/spec/test_to_spec/testfiles/test_unit_api_test.rb +0 -70
- data/test/test_classes.rb +0 -102
- data/test/test_helper.rb +0 -32
@@ -1,196 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'sexp_processor'
|
3
|
-
|
4
|
-
module Spec
|
5
|
-
module TestToSpec
|
6
|
-
# Transforms a Sexp tree (produced by ParseTree) for a Test::Unit class
|
7
|
-
# to a Sexp tree representing an RSpec context
|
8
|
-
class SexpTransformer < SexpProcessor
|
9
|
-
TRANSLATIONS = {
|
10
|
-
:assert_equal => :should_equal,
|
11
|
-
:assert_not_equal => :should_not_equal,
|
12
|
-
:assert_same => :should_be,
|
13
|
-
:assert_not_same => :should_not_be,
|
14
|
-
:assert_instance_of => :should_be_instance_of,
|
15
|
-
:assert_kind_of => :should_be_kind_of,
|
16
|
-
:assert_match => :should_match,
|
17
|
-
:assert_no_match => :should_not_match,
|
18
|
-
:assert_respond_to => :should_respond_to,
|
19
|
-
:assert => :should_be,
|
20
|
-
:assert_nil => :should_be,
|
21
|
-
:assert_not_nil => :should_not_be,
|
22
|
-
:assert_in_delta => :should_be_close,
|
23
|
-
:assert_block => :should_be,
|
24
|
-
:assert_raise => :should_raise,
|
25
|
-
:assert_raises => :should_raise,
|
26
|
-
:assert_nothing_raised => :should_not_raise,
|
27
|
-
:assert_throws => :should_throw,
|
28
|
-
:assert_nothing_thrown => :should_not_throw,
|
29
|
-
}
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
super
|
33
|
-
self.expected = Array
|
34
|
-
@regular_method = false
|
35
|
-
end
|
36
|
-
|
37
|
-
def process_class(exp)
|
38
|
-
# Get the class header
|
39
|
-
exp.shift
|
40
|
-
class_name = exp.shift.to_s.split("::").last
|
41
|
-
context_name = class_name.match(/(.*)Test/)[1]
|
42
|
-
exp.shift
|
43
|
-
|
44
|
-
# Partition all methods (and other stuff) into chunks, as we're
|
45
|
-
# going to handle them a bit differently
|
46
|
-
rest = exp
|
47
|
-
setup, rest = rest.partition{|e| e[0] == :defn && e[1].to_s == "setup"}
|
48
|
-
teardown, rest = rest.partition{|e| e[0] == :defn && e[1].to_s == "teardown"}
|
49
|
-
tests, rest = rest.partition{|e| e[0] == :defn && e[1].to_s =~ /^test/}
|
50
|
-
methods, rest = rest.partition{|e| e[0] == :defn}
|
51
|
-
|
52
|
-
if !methods.empty? && setup.empty?
|
53
|
-
# We have some methods, but no setup to put them in. Create empty setup
|
54
|
-
setup[0] = [:defn, :setup, [:scope, [:block, [:args], [:nil]]]]
|
55
|
-
end
|
56
|
-
|
57
|
-
context_body = []
|
58
|
-
unless setup.empty?
|
59
|
-
setup_block = process(setup.shift)
|
60
|
-
context_body << setup_block
|
61
|
-
end
|
62
|
-
context_body << process(teardown.shift) until teardown.empty?
|
63
|
-
context_body << process(tests.shift) until tests.empty?
|
64
|
-
|
65
|
-
# At this stage we don't want to translate :lvar to :dvar
|
66
|
-
begin
|
67
|
-
@regular_method = true
|
68
|
-
context_body << process(methods.shift) until methods.empty?
|
69
|
-
ensure
|
70
|
-
@regular_method = false
|
71
|
-
end
|
72
|
-
|
73
|
-
context_body << process(rest.shift) until rest.empty?
|
74
|
-
exp.clear
|
75
|
-
|
76
|
-
result = [:iter, [:fcall, :context, [:array, [:str, context_name]]], nil]
|
77
|
-
if context_body.length > 1
|
78
|
-
result << [:block] + context_body
|
79
|
-
else
|
80
|
-
result += context_body
|
81
|
-
end
|
82
|
-
[result]
|
83
|
-
end
|
84
|
-
|
85
|
-
def process_defn(exp)
|
86
|
-
method_name = exp[1].to_s
|
87
|
-
if method_name =~ /^test_(.*)/
|
88
|
-
spec_name = $1.gsub(/_/, " ")
|
89
|
-
|
90
|
-
test_body = exp[2][1][2..-1]
|
91
|
-
exp.clear
|
92
|
-
block_body = []
|
93
|
-
@dasgn_decl = []
|
94
|
-
block_body << process(test_body.shift) until test_body.empty?
|
95
|
-
result = [:iter, [:fcall, :specify, [:array, [:str, spec_name]]], nil]
|
96
|
-
result << [:block] unless block_body == [[:nil]]
|
97
|
-
result[-1] += @dasgn_decl unless @dasgn_decl.empty?
|
98
|
-
result[-1] += block_body unless block_body == [[:nil]]
|
99
|
-
result
|
100
|
-
elsif method_name == "setup" || method_name == "teardown"
|
101
|
-
test_body = exp[2][1][2..-1]
|
102
|
-
exp.clear
|
103
|
-
block_body = []
|
104
|
-
@dasgn_decl = []
|
105
|
-
block_body << process(test_body.shift) until test_body.empty?
|
106
|
-
result = [:iter, [:fcall, method_name.to_sym], nil]
|
107
|
-
result << [:block] unless block_body == [[:nil]]
|
108
|
-
result[-1] += @dasgn_decl unless @dasgn_decl.empty?
|
109
|
-
result[-1] += block_body unless block_body == [[:nil]]
|
110
|
-
result
|
111
|
-
else
|
112
|
-
# Return the same method, but process the innards
|
113
|
-
result = [exp.shift, exp.shift] + process(exp)
|
114
|
-
result
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def process_lasgn(exp)
|
119
|
-
result = exp.dup
|
120
|
-
exp.clear
|
121
|
-
unless @regular_method
|
122
|
-
result[0] = :dasgn_curr
|
123
|
-
decl = result[0..1].dup
|
124
|
-
if @dasgn_decl.empty?
|
125
|
-
@dasgn_decl += [decl]
|
126
|
-
else
|
127
|
-
@dasgn_decl_tail << decl
|
128
|
-
end
|
129
|
-
@dasgn_decl_tail = decl
|
130
|
-
end
|
131
|
-
result
|
132
|
-
end
|
133
|
-
|
134
|
-
# Handles 'block' assert_ calls
|
135
|
-
def process_iter(exp)
|
136
|
-
test_unit_fcall = exp[1][1]
|
137
|
-
rspec_should = TRANSLATIONS[test_unit_fcall]
|
138
|
-
unless rspec_should.nil?
|
139
|
-
body = exp[3]
|
140
|
-
args = exp[1][2]
|
141
|
-
args.delete_at(2) unless args.nil? # get rid of the message arg
|
142
|
-
result = [:call, [:iter, [:fcall, :lambda], nil, body], rspec_should]
|
143
|
-
result << args unless args.nil?
|
144
|
-
result << [:array, [:true]] if test_unit_fcall == :assert_block
|
145
|
-
exp.clear
|
146
|
-
result
|
147
|
-
else
|
148
|
-
exp.shift
|
149
|
-
result = [:iter]
|
150
|
-
result << process(exp.shift) until exp.empty?
|
151
|
-
result
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
# Handles regular assert_ calls
|
156
|
-
def process_fcall(exp)
|
157
|
-
test_unit_fcall = exp[1]
|
158
|
-
rspec_should = TRANSLATIONS[test_unit_fcall]
|
159
|
-
unless rspec_should.nil?
|
160
|
-
args = exp[2]
|
161
|
-
actual_index = [:assert, :assert_not_nil, :assert_nil, :assert_respond_to].index(test_unit_fcall) ? 1 : 2
|
162
|
-
actual = args.delete_at(actual_index)
|
163
|
-
expected = args
|
164
|
-
if test_unit_fcall == :assert_in_delta
|
165
|
-
expected.delete_at(3)
|
166
|
-
expected << args.delete_at(2)
|
167
|
-
else
|
168
|
-
msg_index = (test_unit_fcall == :assert_respond_to) ? 2 : actual_index
|
169
|
-
expected.delete_at(msg_index)
|
170
|
-
end
|
171
|
-
expected << [:true] if test_unit_fcall == :assert
|
172
|
-
expected << [:nil] if [:assert_not_nil, :assert_nil].index(test_unit_fcall)
|
173
|
-
|
174
|
-
actual = process(actual)
|
175
|
-
|
176
|
-
result = [:call, actual, rspec_should, expected]
|
177
|
-
exp.clear
|
178
|
-
result
|
179
|
-
else
|
180
|
-
result = exp.dup
|
181
|
-
exp.clear
|
182
|
-
result
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def process_lvar(exp)
|
187
|
-
result = exp.dup
|
188
|
-
exp.clear
|
189
|
-
unless @regular_method
|
190
|
-
result[0] = :dvar
|
191
|
-
end
|
192
|
-
result
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'parse_tree'
|
3
|
-
require 'spec/test_to_spec/sexp_transformer'
|
4
|
-
require 'spec/test_to_spec/ruby2ruby'
|
5
|
-
|
6
|
-
module Test
|
7
|
-
module Unit
|
8
|
-
class TestCase
|
9
|
-
# Returns a String representing the RSpec translation of this class
|
10
|
-
def self.to_rspec
|
11
|
-
tree = ParseTree.new.parse_tree(self).first
|
12
|
-
rspec_tree = Spec::TestToSpec::SexpTransformer.new.process(tree)
|
13
|
-
modules = self.name.split("::")[0..-2]
|
14
|
-
result = ""
|
15
|
-
result += modules.collect{|m| "module #{m}\n"}.join("")
|
16
|
-
result += RubyToRuby.new.process(rspec_tree[0])
|
17
|
-
result += modules.collect{|m| "\nend"}.join("")
|
18
|
-
result
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'spec/test_to_spec/test_case_ext'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'erb'
|
4
|
-
|
5
|
-
module Spec
|
6
|
-
module TestToSpec
|
7
|
-
# A Test::Unit runner that doesn't run tests, but translates them instead!
|
8
|
-
class TranslationTestRunner
|
9
|
-
include FileUtils
|
10
|
-
|
11
|
-
def self.run(suite, output_level)
|
12
|
-
self.new(suite)
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(suite)
|
16
|
-
log "Writing translated specs to #{$test2spec_options[:specdir]}"
|
17
|
-
ObjectSpace.each_object(Class) do |klass|
|
18
|
-
if klass < ::Test::Unit::TestCase
|
19
|
-
begin
|
20
|
-
translation = klass.to_rspec
|
21
|
-
|
22
|
-
unless $test2spec_options[:dry_run]
|
23
|
-
relative_path = underscore(klass.name)
|
24
|
-
template = $test2spec_options[:template] ? IO.read($test2spec_options[:template]) : nil
|
25
|
-
source = render(translation, relative_path, template)
|
26
|
-
|
27
|
-
relative_path.gsub! /_test$/, "_spec"
|
28
|
-
relative_path += ".rb"
|
29
|
-
write(source, relative_path)
|
30
|
-
else
|
31
|
-
log "Successfully translated #{klass}"
|
32
|
-
end
|
33
|
-
rescue => e
|
34
|
-
log "Failed to translate #{klass}"
|
35
|
-
verbose "Message: #{e.message}"
|
36
|
-
verbose e.backtrace.join("\n")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
puts "\nDone"
|
41
|
-
end
|
42
|
-
|
43
|
-
def passed?
|
44
|
-
true
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def render(translation, relative_path, template)
|
50
|
-
unless template.nil?
|
51
|
-
depth = relative_path.split('/').length-1
|
52
|
-
erb = ERB.new(template)
|
53
|
-
erb.result(binding)
|
54
|
-
else
|
55
|
-
translation
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def log(msg)
|
60
|
-
puts msg unless quiet?
|
61
|
-
end
|
62
|
-
|
63
|
-
def quiet?
|
64
|
-
$test2spec_options[:quiet] == true
|
65
|
-
end
|
66
|
-
|
67
|
-
def verbose(msg)
|
68
|
-
puts msg if verbose?
|
69
|
-
end
|
70
|
-
|
71
|
-
def verbose?
|
72
|
-
!quiet? && $test2spec_options[:verbose] == true
|
73
|
-
end
|
74
|
-
|
75
|
-
def destination_path(relative_destination)
|
76
|
-
File.join($test2spec_options[:specdir], relative_destination)
|
77
|
-
end
|
78
|
-
|
79
|
-
def write(source, relative_destination)
|
80
|
-
destination = destination_path(relative_destination)
|
81
|
-
destination_exists = File.exists?(destination)
|
82
|
-
if destination_exists and identical?(source, destination)
|
83
|
-
return log("Identical : #{relative_destination}")
|
84
|
-
end
|
85
|
-
|
86
|
-
if destination_exists
|
87
|
-
choice = case ($test2spec_options[:collision]).to_sym #|| :ask
|
88
|
-
when :ask then force_file_collision?(relative_destination)
|
89
|
-
when :force then :force
|
90
|
-
when :skip then :skip
|
91
|
-
end
|
92
|
-
|
93
|
-
case choice
|
94
|
-
when :force then log("Forcing : #{relative_destination}")
|
95
|
-
when :skip then return(log("Skipping : #{relative_destination}"))
|
96
|
-
end
|
97
|
-
else
|
98
|
-
dir = File.dirname(destination)
|
99
|
-
unless File.directory?(dir)
|
100
|
-
log "Creating : #{dir}"
|
101
|
-
mkdir_p dir
|
102
|
-
end
|
103
|
-
log "Creating : #{destination}"
|
104
|
-
end
|
105
|
-
|
106
|
-
File.open(destination, 'w') do |df|
|
107
|
-
df.write(source)
|
108
|
-
end
|
109
|
-
|
110
|
-
if $test2spec_options[:chmod]
|
111
|
-
chmod($test2spec_options[:chmod], destination)
|
112
|
-
end
|
113
|
-
|
114
|
-
system("svn add #{destination}") if $test2spec_options[:svn]
|
115
|
-
end
|
116
|
-
|
117
|
-
def identical?(source, destination, &block)
|
118
|
-
return false if File.directory? destination
|
119
|
-
destination = IO.read(destination)
|
120
|
-
source == destination
|
121
|
-
end
|
122
|
-
|
123
|
-
def force_file_collision?(destination)
|
124
|
-
$stdout.print "overwrite #{destination}? [Ynaq] "
|
125
|
-
case $stdin.gets
|
126
|
-
when /a/i
|
127
|
-
$test2spec_options[:collision] = :force
|
128
|
-
log "Forcing ALL"
|
129
|
-
:force
|
130
|
-
when /q/i
|
131
|
-
puts "Quitting"
|
132
|
-
raise SystemExit
|
133
|
-
when /n/i then :skip
|
134
|
-
else :force
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def underscore(camel_cased_word)
|
139
|
-
camel_cased_word.to_s.gsub(/::/, '/').
|
140
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
141
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
142
|
-
tr("-", "_").
|
143
|
-
downcase
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Expectations
|
5
|
-
module Helper
|
6
|
-
|
7
|
-
class ArbitraryOperatorTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
# == arg
|
10
|
-
|
11
|
-
def test_should_pass_when_equals_operator_passes
|
12
|
-
assert_nothing_raised do
|
13
|
-
(2+2).should == 4
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_fail_when_equals_operator_fails
|
18
|
-
assert_raise(ExpectationNotMetError) do
|
19
|
-
(2+2).should == 5
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# =~ arg
|
24
|
-
|
25
|
-
def test_should_pass_when_match_operator_passes
|
26
|
-
assert_nothing_raised do
|
27
|
-
"foo".should =~ /oo/
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_fail_when_match_operator_fails
|
32
|
-
assert_raise(ExpectationNotMetError) do
|
33
|
-
"fu".should =~ /oo/
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# < and >
|
38
|
-
|
39
|
-
def test_should_pass_when_comparison_passes
|
40
|
-
assert_nothing_raised do
|
41
|
-
3.should_be < 4
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_should_fail_when_comparison_fails
|
46
|
-
assert_raise(ExpectationNotMetError) do
|
47
|
-
3.should_be > 4
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
-
|
3
|
-
module Spec
|
4
|
-
module Expectations
|
5
|
-
module Helper
|
6
|
-
|
7
|
-
class ShouldBeArbitraryPredicateTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
# should_be_<predicate>
|
10
|
-
|
11
|
-
def test_should_pass_when_predicate_returns_true
|
12
|
-
mock = HandCodedMock.new(true)
|
13
|
-
assert_nothing_raised do
|
14
|
-
mock.should_be_funny
|
15
|
-
end
|
16
|
-
mock.__verify
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_should_fail_when_predicate_returns_false
|
20
|
-
mock = HandCodedMock.new(false)
|
21
|
-
assert_raise(ExpectationNotMetError) do
|
22
|
-
mock.should_be_funny
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_fail_when_predicate_returns_nil
|
27
|
-
mock = HandCodedMock.new(nil)
|
28
|
-
assert_raise(ExpectationNotMetError) do
|
29
|
-
mock.should_be_funny
|
30
|
-
end
|
31
|
-
mock.__verify
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_fail_when_method_returns_something_other_than_true_false_or_nil
|
35
|
-
mock = HandCodedMock.new(5)
|
36
|
-
assert_nothing_raised do
|
37
|
-
mock.should_be_funny
|
38
|
-
end
|
39
|
-
mock.__verify
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_raise_when_target_does_not_respond_to_predicate
|
43
|
-
assert_raise(NoMethodError) do
|
44
|
-
5.should_be_funny
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# should_be_funny(args)
|
49
|
-
|
50
|
-
def test_should_pass_when_predicate_accepts_args_and_returns_true
|
51
|
-
mock = HandCodedMock.new(true)
|
52
|
-
assert_nothing_raised do
|
53
|
-
mock.should_be_hungry(1, 2, 3)
|
54
|
-
end
|
55
|
-
mock.__verify
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_should_fail_when_predicate_accepts_args_and_returns_false
|
59
|
-
mock = HandCodedMock.new(false)
|
60
|
-
assert_raise(ExpectationNotMetError) do
|
61
|
-
mock.should_be_hungry(1, 2, 3)
|
62
|
-
end
|
63
|
-
mock.__verify
|
64
|
-
end
|
65
|
-
|
66
|
-
# should_exist => exists?
|
67
|
-
|
68
|
-
def test_should_support_plural_form
|
69
|
-
mock = HandCodedMock.new(true)
|
70
|
-
assert_nothing_raised do
|
71
|
-
mock.should_exist
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_should_support_multi_word_predicates_with_should
|
76
|
-
assert_nothing_raised do
|
77
|
-
HandCodedMock.new(true).should_multi_word_predicate
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_should_support_multi_word_predicates_with_should_be
|
82
|
-
assert_nothing_raised do
|
83
|
-
HandCodedMock.new(true).should_be_multi_word_predicate
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class ShouldNotBeArbitraryPredicateTest < Test::Unit::TestCase
|
90
|
-
|
91
|
-
# should_not_be_funny
|
92
|
-
|
93
|
-
def test_should_pass_when_predicate_returns_false
|
94
|
-
mock = HandCodedMock.new(false)
|
95
|
-
assert_nothing_raised do
|
96
|
-
mock.should_not_be_funny
|
97
|
-
end
|
98
|
-
mock.__verify
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_should_fail_when_predicate_returns_true
|
102
|
-
mock = HandCodedMock.new(true)
|
103
|
-
assert_raise(ExpectationNotMetError) do
|
104
|
-
mock.should_not_be_funny
|
105
|
-
end
|
106
|
-
mock.__verify
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_should_pass_when_predicate_returns_nil
|
110
|
-
mock = HandCodedMock.new(nil)
|
111
|
-
assert_nothing_raised do
|
112
|
-
mock.should_not_be_funny
|
113
|
-
end
|
114
|
-
mock.__verify
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_fail_when_method_returns_something_other_than_true_false_or_nil
|
118
|
-
mock = HandCodedMock.new(5)
|
119
|
-
assert_raise(ExpectationNotMetError) do
|
120
|
-
mock.should_not_be_funny
|
121
|
-
end
|
122
|
-
mock.__verify
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_should_raise_when_target_does_not_respond_to_predicate
|
126
|
-
assert_raise(NoMethodError) do
|
127
|
-
5.should_not_be_funny
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# should_be_funny(args)
|
132
|
-
|
133
|
-
def test_should_fail_when_predicate_accepts_args_and_returns_true
|
134
|
-
mock = HandCodedMock.new(true)
|
135
|
-
assert_raise(ExpectationNotMetError) do
|
136
|
-
mock.should_not_be_hungry(1, 2, 3)
|
137
|
-
end
|
138
|
-
mock.__verify
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_should_pass_when_predicate_accepts_args_and_returns_false
|
142
|
-
mock = HandCodedMock.new(false)
|
143
|
-
assert_nothing_raised do
|
144
|
-
mock.should_not_be_hungry(1, 2, 3)
|
145
|
-
end
|
146
|
-
mock.__verify
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_support_multi_word_predicates_with_should
|
150
|
-
assert_nothing_raised do
|
151
|
-
HandCodedMock.new(false).should_not_multi_word_predicate
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_should_support_multi_word_predicates_with_should_be
|
156
|
-
assert_nothing_raised do
|
157
|
-
HandCodedMock.new(false).should_not_be_multi_word_predicate
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|