synthesis 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +32 -2
- data/lib/synthesis/adapter/expectations.rb +1 -0
- data/lib/synthesis/adapter/rspec.rb +11 -5
- data/lib/synthesis/recordable.rb +1 -1
- data/lib/synthesis/task.rb +8 -3
- data/synthesis.gemspec +41 -0
- metadata +6 -30
- data/test/synthesis/adapter/mocha/expectation_record_test.rb +0 -15
- data/test/synthesis/adapter/mocha/helper.rb +0 -3
- data/test/synthesis/adapter/mocha/mocha_expectation_test.rb +0 -26
- data/test/synthesis/adapter/mocha/mocha_test.rb +0 -9
- data/test/synthesis/adapter/mocha/object_test.rb +0 -18
- data/test/synthesis/adapter/rspec/expectation_record_test.rb +0 -15
- data/test/synthesis/adapter/rspec/helper.rb +0 -3
- data/test/synthesis/adapter/rspec/message_expectation_test.rb +0 -19
- data/test/synthesis/adapter/rspec/methods_test.rb +0 -22
- data/test/synthesis/class_test.rb +0 -7
- data/test/synthesis/expectation_matcher_test.rb +0 -54
- data/test/synthesis/expectation_record_test.rb +0 -89
- data/test/synthesis/expectation_test.rb +0 -112
- data/test/synthesis/helper.rb +0 -3
- data/test/synthesis/method_invocation_watcher_test.rb +0 -18
- data/test/synthesis/module_test.rb +0 -7
- data/test/synthesis/object_test.rb +0 -7
- data/test/synthesis/recordable_test.rb +0 -116
- data/test_project/expectations/test/data_brander_test.rb +0 -18
- data/test_project/expectations/test/storage_test.rb +0 -21
- data/test_project/mocha/test/data_brander_test.rb +0 -36
- data/test_project/mocha/test/storage_test.rb +0 -31
- data/test_project/rspec/data_brander_spec.rb +0 -36
- data/test_project/rspec/storage_spec.rb +0 -30
- data/test_project/test_project.rb +0 -47
data/Rakefile
CHANGED
|
@@ -7,7 +7,7 @@ require File.dirname(__FILE__) + "/lib/synthesis/task"
|
|
|
7
7
|
|
|
8
8
|
load 'synthesis.gemspec'
|
|
9
9
|
|
|
10
|
-
task :default => :test
|
|
10
|
+
task :default => [:test, "test_project:all"]
|
|
11
11
|
|
|
12
12
|
desc "Run all tests"
|
|
13
13
|
task :test => %w[test:core test:mocha test:spec]
|
|
@@ -43,6 +43,26 @@ Synthesis::Task.new('synthesis:spec') do |t|
|
|
|
43
43
|
t.pattern = 'test_project/rspec/*_spec.rb'
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
namespace :test_project do
|
|
47
|
+
task :all do
|
|
48
|
+
STDOUT.puts `rake test_project:mocha`
|
|
49
|
+
STDOUT.puts `rake test_project:rspec`
|
|
50
|
+
STDOUT.puts `rake test_project:expectations`
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
Rake::TestTask.new('mocha') do |t|
|
|
54
|
+
t.pattern = 'test_project/mocha/**/*_test.rb'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
Rake::TestTask.new('rspec') do |t|
|
|
58
|
+
t.pattern = 'test_project/mocha/**/*_test.rb'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
Rake::TestTask.new('expectations') do |t|
|
|
62
|
+
t.pattern = 'test_project/mocha/**/*_test.rb'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
46
66
|
desc 'Generate RDoc'
|
|
47
67
|
Rake::RDocTask.new do |task|
|
|
48
68
|
task.main = 'README'
|
|
@@ -64,4 +84,14 @@ Rake::GemPackageTask.new(GEMSPEC) do |t|
|
|
|
64
84
|
end
|
|
65
85
|
|
|
66
86
|
desc "Remove rdoc and package artefacts"
|
|
67
|
-
task :clean => %w[clobber_package clobber_rdoc]
|
|
87
|
+
task :clean => %w[clobber_package clobber_rdoc]
|
|
88
|
+
|
|
89
|
+
task(:lf) {p Dir["lib/**/*rb"] }
|
|
90
|
+
|
|
91
|
+
task(:check_gemspec) do
|
|
92
|
+
require 'rubygems/specification'
|
|
93
|
+
data = File.read('synthesis.gemspec')
|
|
94
|
+
spec = nil
|
|
95
|
+
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
|
96
|
+
puts spec
|
|
97
|
+
end
|
|
@@ -18,6 +18,7 @@ module Synthesis
|
|
|
18
18
|
Mocha::Expectation.record_expected_arguments_on(:with)
|
|
19
19
|
Mocha::Expectation.record_expected_return_values_on(:returns)
|
|
20
20
|
Mocha::Expectation.record_expected_return_values_on(:raises)
|
|
21
|
+
Mocha::Expectation.remove_expectation_on(:never)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def stop_collecting_expectations
|
|
@@ -7,11 +7,11 @@ require File.dirname(__FILE__) + "/../../synthesis"
|
|
|
7
7
|
module Synthesis
|
|
8
8
|
class RSpecAdapter < Adapter
|
|
9
9
|
def run
|
|
10
|
-
|
|
10
|
+
Synthesis.rspec_runner_options.files.clear
|
|
11
11
|
fail_unless do
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
|
|
12
|
+
Synthesis.rspec_runner_options.instance_variable_set(:@formatters, nil)
|
|
13
|
+
# Synthesis.rspec_runner_options.instance_variable_set(:@format_options, [["profile", STDOUT]])
|
|
14
|
+
Synthesis.rspec_runner_options.run_examples
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -30,5 +30,11 @@ module Synthesis
|
|
|
30
30
|
Spec::Mocks::MessageExpectation.stop_intercepting!
|
|
31
31
|
Spec::Mocks::Methods.stop_recording!
|
|
32
32
|
end
|
|
33
|
-
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def rspec_runner_options
|
|
36
|
+
Spec::Runner.options rescue rspec_options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module_function :rspec_runner_options
|
|
34
40
|
end
|
data/lib/synthesis/recordable.rb
CHANGED
data/lib/synthesis/task.rb
CHANGED
|
@@ -6,10 +6,10 @@ require File.dirname(__FILE__) + "/../synthesis/logging"
|
|
|
6
6
|
module Synthesis
|
|
7
7
|
class Task < Rake::TaskLib
|
|
8
8
|
include Logging
|
|
9
|
-
attr_accessor :verbose, :pattern, :ruby_opts, :adapter, :out, :ignored
|
|
9
|
+
attr_accessor :verbose, :pattern, :ruby_opts, :adapter, :out, :ignored, :libs
|
|
10
10
|
|
|
11
11
|
def initialize(name='synthesis:test')
|
|
12
|
-
@name, @ignored = name, []
|
|
12
|
+
@name, @ignored, @libs = name, [], []
|
|
13
13
|
yield self if block_given?
|
|
14
14
|
@pattern ||= 'test/**/*_test.rb'
|
|
15
15
|
@ruby_opts ||= []
|
|
@@ -32,7 +32,7 @@ module Synthesis
|
|
|
32
32
|
desc "Run Synthesis tests"
|
|
33
33
|
task @name do
|
|
34
34
|
RakeFileUtils.verbose(@verbose) do
|
|
35
|
-
|
|
35
|
+
load_paths
|
|
36
36
|
require File.dirname(__FILE__) + "/../synthesis"
|
|
37
37
|
require File.dirname(__FILE__) + "/../synthesis/runner"
|
|
38
38
|
Synthesis::Logging.const_set(:OUT, @out) if @out
|
|
@@ -42,5 +42,10 @@ module Synthesis
|
|
|
42
42
|
end
|
|
43
43
|
self
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
def load_paths
|
|
48
|
+
@libs.each { |path| $:.unshift(File.join(Dir.pwd, path)) }
|
|
49
|
+
end
|
|
45
50
|
end
|
|
46
51
|
end
|
data/synthesis.gemspec
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
GEMSPEC =Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'synthesis'
|
|
3
|
+
s.version = '0.1.6'
|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
|
5
|
+
s.rubyforge_project = "synthesis"
|
|
6
|
+
s.summary, s.description = 'A tool for Synthesized Testing'
|
|
7
|
+
s.authors = 'Stuart Caborn, George Malamidis'
|
|
8
|
+
s.email = 'george@nutrun.com'
|
|
9
|
+
s.homepage = 'http://synthesis.rubyforge.org'
|
|
10
|
+
s.has_rdoc = true
|
|
11
|
+
s.rdoc_options += ['--quiet', '--title', 'Synthesis', '--main', 'README', '--inline-source']
|
|
12
|
+
s.extra_rdoc_files = ['README', 'COPYING']
|
|
13
|
+
s.files = [
|
|
14
|
+
"COPYING",
|
|
15
|
+
"Rakefile",
|
|
16
|
+
"README",
|
|
17
|
+
"synthesis.gemspec",
|
|
18
|
+
"lib/synthesis/adapter/expectations.rb",
|
|
19
|
+
"lib/synthesis/adapter/mocha.rb",
|
|
20
|
+
"lib/synthesis/adapter/rspec.rb",
|
|
21
|
+
"lib/synthesis/adapter.rb",
|
|
22
|
+
"lib/synthesis/class.rb",
|
|
23
|
+
"lib/synthesis/expectation.rb",
|
|
24
|
+
"lib/synthesis/expectation_interceptor.rb",
|
|
25
|
+
"lib/synthesis/expectation_matcher.rb",
|
|
26
|
+
"lib/synthesis/expectation_record.rb",
|
|
27
|
+
"lib/synthesis/expectation_record_enabled.rb",
|
|
28
|
+
"lib/synthesis/logging.rb",
|
|
29
|
+
"lib/synthesis/method_invocation_watcher.rb",
|
|
30
|
+
"lib/synthesis/module.rb",
|
|
31
|
+
"lib/synthesis/object.rb",
|
|
32
|
+
"lib/synthesis/recordable.rb",
|
|
33
|
+
"lib/synthesis/reporter.rb",
|
|
34
|
+
"lib/synthesis/runner.rb",
|
|
35
|
+
"lib/synthesis/task.rb",
|
|
36
|
+
"lib/synthesis/util/mock_instance/mocha.rb",
|
|
37
|
+
"lib/synthesis/util/mock_instance/rspec.rb",
|
|
38
|
+
"lib/synthesis/util/mock_instance.rb",
|
|
39
|
+
"lib/synthesis.rb"
|
|
40
|
+
]
|
|
41
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: synthesis
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stuart Caborn, George Malamidis
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2008-
|
|
12
|
+
date: 2008-10-17 00:00:00 +01:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -23,6 +23,10 @@ extra_rdoc_files:
|
|
|
23
23
|
- README
|
|
24
24
|
- COPYING
|
|
25
25
|
files:
|
|
26
|
+
- COPYING
|
|
27
|
+
- Rakefile
|
|
28
|
+
- README
|
|
29
|
+
- synthesis.gemspec
|
|
26
30
|
- lib/synthesis/adapter/expectations.rb
|
|
27
31
|
- lib/synthesis/adapter/mocha.rb
|
|
28
32
|
- lib/synthesis/adapter/rspec.rb
|
|
@@ -45,34 +49,6 @@ files:
|
|
|
45
49
|
- lib/synthesis/util/mock_instance/rspec.rb
|
|
46
50
|
- lib/synthesis/util/mock_instance.rb
|
|
47
51
|
- lib/synthesis.rb
|
|
48
|
-
- test/synthesis/adapter/mocha/expectation_record_test.rb
|
|
49
|
-
- test/synthesis/adapter/mocha/helper.rb
|
|
50
|
-
- test/synthesis/adapter/mocha/mocha_expectation_test.rb
|
|
51
|
-
- test/synthesis/adapter/mocha/mocha_test.rb
|
|
52
|
-
- test/synthesis/adapter/mocha/object_test.rb
|
|
53
|
-
- test/synthesis/adapter/rspec/expectation_record_test.rb
|
|
54
|
-
- test/synthesis/adapter/rspec/helper.rb
|
|
55
|
-
- test/synthesis/adapter/rspec/message_expectation_test.rb
|
|
56
|
-
- test/synthesis/adapter/rspec/methods_test.rb
|
|
57
|
-
- test/synthesis/class_test.rb
|
|
58
|
-
- test/synthesis/expectation_matcher_test.rb
|
|
59
|
-
- test/synthesis/expectation_record_test.rb
|
|
60
|
-
- test/synthesis/expectation_test.rb
|
|
61
|
-
- test/synthesis/helper.rb
|
|
62
|
-
- test/synthesis/method_invocation_watcher_test.rb
|
|
63
|
-
- test/synthesis/module_test.rb
|
|
64
|
-
- test/synthesis/object_test.rb
|
|
65
|
-
- test/synthesis/recordable_test.rb
|
|
66
|
-
- test_project/expectations/test/data_brander_test.rb
|
|
67
|
-
- test_project/expectations/test/storage_test.rb
|
|
68
|
-
- test_project/mocha/test/data_brander_test.rb
|
|
69
|
-
- test_project/mocha/test/storage_test.rb
|
|
70
|
-
- test_project/rspec/data_brander_spec.rb
|
|
71
|
-
- test_project/rspec/storage_spec.rb
|
|
72
|
-
- test_project/test_project.rb
|
|
73
|
-
- COPYING
|
|
74
|
-
- README
|
|
75
|
-
- Rakefile
|
|
76
52
|
has_rdoc: true
|
|
77
53
|
homepage: http://synthesis.rubyforge.org
|
|
78
54
|
post_install_message:
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ExpectationRecordTest < Test::Unit::TestCase
|
|
5
|
-
def teardown
|
|
6
|
-
ExpectationRecord.send(:reset!)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_does_not_add_any_instance_expectation
|
|
10
|
-
any = Class::AnyInstance.new(Object)
|
|
11
|
-
ExpectationRecord.add_expectation(any, :foo, :track)
|
|
12
|
-
assert_equal(0, ExpectationRecord.expectations.size)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
class MochaExpectationTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
@mocha_expectation = Mocha::Expectation.new(:mock, :blah)
|
|
6
|
-
@synthesis_expectation = Synthesis::Expectation.new(Hash, :method, :track, [], [1])
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_holds_synthesis_expectation
|
|
10
|
-
@mocha_expectation.synthesis_expectation = @synthesis_expectation
|
|
11
|
-
assert_equal(@synthesis_expectation, @mocha_expectation.synthesis_expectation)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_with_passes_expected_params_to_synthesis_expectation
|
|
15
|
-
@mocha_expectation.synthesis_expectation = @synthesis_expectation
|
|
16
|
-
@mocha_expectation.with(1, 2)
|
|
17
|
-
assert_equal([1, 2], @mocha_expectation.synthesis_expectation.args)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_passes_return_values_to_synthesis_expectation
|
|
21
|
-
@mocha_expectation.synthesis_expectation = @synthesis_expectation
|
|
22
|
-
@mocha_expectation.returns(:rock)
|
|
23
|
-
return_values = @synthesis_expectation.instance_variable_get(:@return_values)
|
|
24
|
-
assert_equal([1, :rock], return_values)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ObjectTest < Test::Unit::TestCase
|
|
5
|
-
def test_records_singleton_method_expectation
|
|
6
|
-
ExpectationRecord.expects(:add_expectation).with(Hash, :foo, kind_of(String))
|
|
7
|
-
Hash.expects(:foo)
|
|
8
|
-
Hash.foo
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_records_instance_method_expectation
|
|
12
|
-
hash = Hash.new
|
|
13
|
-
ExpectationRecord.expects(:add_expectation).with(hash, :foo, kind_of(String))
|
|
14
|
-
hash.expects(:foo)
|
|
15
|
-
hash.foo
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ExpectationRecordTest < Test::Unit::TestCase
|
|
5
|
-
def teardown
|
|
6
|
-
ExpectationRecord.send(:reset!)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_does_not_add_any_instance_expectation
|
|
10
|
-
mock = Spec::Mocks::Mock.new(Numeric)
|
|
11
|
-
ExpectationRecord.add_expectation(mock, :foo, :track)
|
|
12
|
-
assert_equal(0, ExpectationRecord.expectations.size)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
class MessageExpectationTest < Test::Unit::TestCase
|
|
4
|
-
def setup
|
|
5
|
-
error_generator = Class.new {def opts=(param)end}.new
|
|
6
|
-
@spec_expectation = Spec::Mocks::MessageExpectation.new(error_generator, :n, :n, :n, :n)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_holds_synthesis_expectation
|
|
10
|
-
@spec_expectation.synthesis_expectation = 1
|
|
11
|
-
assert_equal 1, @spec_expectation.synthesis_expectation
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_with_passes_expected_params_to_synthesis_expectation
|
|
15
|
-
@spec_expectation.synthesis_expectation = Synthesis::Expectation.new(Hash, :foo, :track)
|
|
16
|
-
@spec_expectation.with 1, 2
|
|
17
|
-
assert_equal([1, 2], @spec_expectation.synthesis_expectation.args)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class MethodsTest < Test::Unit::TestCase
|
|
5
|
-
def teardown
|
|
6
|
-
ExpectationRecord.send(:reset!)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_records_singleton_method_expectation
|
|
10
|
-
ExpectationRecord.should_receive(:add_expectation).with(Hash, :foo, an_instance_of(String))
|
|
11
|
-
Hash.should_receive(:foo)
|
|
12
|
-
Hash.foo
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_records_instance_method_expectation
|
|
16
|
-
hash = Hash.new
|
|
17
|
-
ExpectationRecord.should_receive(:add_expectation).with(hash, :foo, an_instance_of(String))
|
|
18
|
-
hash.should_receive(:foo)
|
|
19
|
-
hash.foo
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ExpectationMatcherTest < Test::Unit::TestCase
|
|
5
|
-
def test_match
|
|
6
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
7
|
-
exp2 = Expectation.new(Object.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
8
|
-
assert(ExpectationMatcher.new(exp1, exp2).match?)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_no_match_based_on_expectation_type
|
|
12
|
-
exp1 = Expectation.new(Array, :foo, :track, [Array, Hash], [Array, Hash])
|
|
13
|
-
exp2 = Expectation.new(Array.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
14
|
-
assert(!ExpectationMatcher.new(exp1, exp2).match?)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_no_match_based_on_receiver_type
|
|
18
|
-
exp1 = Expectation.new(Array.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
19
|
-
exp2 = Expectation.new(Hash.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
20
|
-
assert(!ExpectationMatcher.new(exp1, exp2).match?)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_no_match_based_on_method_name
|
|
24
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [Array, Hash], [Array, Hash])
|
|
25
|
-
exp2 = Expectation.new(Object.new, :bar, :track, [Array, Hash], [Array, Hash])
|
|
26
|
-
assert(!ExpectationMatcher.new(exp1, exp2).match?)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_no_match_based_on_arg_types
|
|
30
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [1, "a"], [Array, Hash])
|
|
31
|
-
exp2 = Expectation.new(Object.new, :foo, :track, [1, 2], [Array, Hash])
|
|
32
|
-
assert(!ExpectationMatcher.new(exp1, exp2).match?)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_no_match_based_on_return_value_types
|
|
36
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [Array, Hash])
|
|
37
|
-
exp1.add_return_values(:sym)
|
|
38
|
-
exp2 = Expectation.new(Object.new, :foo, :track, [Array, Hash], ["string"])
|
|
39
|
-
assert(!ExpectationMatcher.new(exp1, exp2).match?)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_match_based_on_return_value_types
|
|
43
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [Array, Hash], [[1], {:a => :b}])
|
|
44
|
-
exp2 = Expectation.new(Object.new, :foo, :track, [Array, Hash], [[4], {:a => 9}])
|
|
45
|
-
assert(ExpectationMatcher.new(exp1, exp2).match?)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def test_ignores_return_value_types_unless_return_values_defined
|
|
49
|
-
exp1 = Expectation.new(Object.new, :foo, :track, [Array, Hash])
|
|
50
|
-
exp2 = Expectation.new(Object.new, :foo, :track, [Array, Hash])
|
|
51
|
-
assert(ExpectationMatcher.new(exp1, exp2).match?)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ExpectationRecordTest < Test::Unit::TestCase
|
|
5
|
-
def teardown
|
|
6
|
-
ExpectationRecord.send(:reset!)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_adds_expectation
|
|
10
|
-
ExpectationRecord.add_expectation(Object.new, :to_s, :track)
|
|
11
|
-
assert_equal(1, ExpectationRecord.expectations.size)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def test_watches_expectation_invocations
|
|
15
|
-
c = Class.new { def foo; end }
|
|
16
|
-
ExpectationRecord.add_expectation(c.new, :foo, :track)
|
|
17
|
-
ExpectationRecord.record_invocations
|
|
18
|
-
a = c.new
|
|
19
|
-
MethodInvocationWatcher.expects(:invoked).with(a, :foo, [], [nil])
|
|
20
|
-
a.foo
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_finds_expectation
|
|
24
|
-
c = Class.new { def foo; end }
|
|
25
|
-
expected = ExpectationRecord.add_expectation(c.new, :foo, :track)
|
|
26
|
-
expected.add_return_values(20)
|
|
27
|
-
ExpectationRecord.record_invocations
|
|
28
|
-
matcher = Expectation.new(c.new, :foo, :track, [], [20])
|
|
29
|
-
actual = ExpectationRecord[matcher]
|
|
30
|
-
assert_equal(expected, actual)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_returns_nil_expectation_on_no_expectation_found
|
|
34
|
-
ExpectationRecord.add_expectation(Object.new, :foo, :track)
|
|
35
|
-
matcher = Expectation.new(Object.new, :bar, :track)
|
|
36
|
-
actual_instance = ExpectationRecord[matcher]
|
|
37
|
-
assert_kind_of(Expectation::NilExpectation, actual_instance)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_does_not_add_expectation_for_ignored_class
|
|
41
|
-
ExpectationRecord.ignore(Hash)
|
|
42
|
-
ExpectationRecord.add_expectation(Hash, :foo, :track)
|
|
43
|
-
assert(ExpectationRecord.expectations.empty?)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_does_not_add_expectation_for_ignored_object
|
|
47
|
-
ExpectationRecord.ignore(Hash)
|
|
48
|
-
ExpectationRecord.add_expectation(Hash.new, :foo, :track)
|
|
49
|
-
assert(ExpectationRecord.expectations.empty?)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_does_not_add_expectation_for_ignored_module
|
|
53
|
-
ExpectationRecord.ignore(Enumerable)
|
|
54
|
-
ExpectationRecord.add_expectation(Enumerable, :foo, :track)
|
|
55
|
-
assert(ExpectationRecord.expectations.empty?)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def test_returns_added_expectation_on_add
|
|
59
|
-
expected = Expectation.new(Hash, :foo, :track, [], [:return_val])
|
|
60
|
-
actual = ExpectationRecord.add_expectation(Hash, :foo, :track)
|
|
61
|
-
actual.add_return_values(:return_val)
|
|
62
|
-
assert_equal(expected, actual)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def test_uniqs_expectations_before_recording_invocations
|
|
66
|
-
c = Class.new { def foo; end }
|
|
67
|
-
ExpectationRecord.add_expectation(c, :foo, :track)
|
|
68
|
-
ExpectationRecord.add_expectation(c, :foo, :track)
|
|
69
|
-
assert_equal(2, ExpectationRecord.expectations.size)
|
|
70
|
-
ExpectationRecord.record_invocations
|
|
71
|
-
assert_equal(1, ExpectationRecord.expectations.size)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_flattens_expectations_before_recording_invocations
|
|
75
|
-
c = Class.new { def foo; end }
|
|
76
|
-
expectation = ExpectationRecord.add_expectation(c, :foo, :track)
|
|
77
|
-
expectation.add_return_values(1, "str", "sym")
|
|
78
|
-
ExpectationRecord.record_invocations
|
|
79
|
-
ExpectationRecord.expectations.each { |val| assert(!val.is_a?(Array)) }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_removes_expectation
|
|
83
|
-
c = Class.new { def foo; end }
|
|
84
|
-
expectation = ExpectationRecord.add_expectation(c, :foo, :track)
|
|
85
|
-
ExpectationRecord.remove(expectation)
|
|
86
|
-
assert_equal(0, ExpectationRecord.expectations.size)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class ExpectationTest < Test::Unit::TestCase
|
|
5
|
-
def test_creates_singleton_method_expectation_given_class
|
|
6
|
-
expectation = Expectation.new(Class.new, :foo, :track)
|
|
7
|
-
assert_kind_of(Expectation::Singleton, expectation)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_creates_instance_method_expectation_given_instance
|
|
11
|
-
expectation = Expectation.new(Class.new.new, :foo, :track)
|
|
12
|
-
assert_kind_of(Expectation::Instance, expectation)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_creates_singleton_method_expectation_given_module
|
|
16
|
-
expectation = Expectation.new(Module.new, :foo, :track)
|
|
17
|
-
assert_kind_of(Expectation::Singleton, expectation)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_records_instance_receiver_method_invocations
|
|
21
|
-
receiver = Class.new { def foo;end }
|
|
22
|
-
expectation = Expectation.new(receiver.new, :foo, :track)
|
|
23
|
-
expectation.record_invocations
|
|
24
|
-
assert_respond_to(receiver.new, :__recordable__foo)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_records_singleton_receiver_method_invocations
|
|
28
|
-
receiver = Class.new { def self.foo;end }
|
|
29
|
-
expectation = Expectation.new(receiver, :foo, :track, [], [:return])
|
|
30
|
-
expectation.record_invocations
|
|
31
|
-
assert_respond_to(receiver, :__recordable__foo)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_make_sure_equality_works_with_uniq
|
|
35
|
-
expectations = [
|
|
36
|
-
Expectation.new(String, :new, [], [:arg1, :arg2], [:return]),
|
|
37
|
-
Expectation.new(String, :new, [], [:arg1, :arg2], [:return])
|
|
38
|
-
]
|
|
39
|
-
assert_equal(1, expectations.uniq.size)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_singleton_receiver_class
|
|
43
|
-
assert_equal(String, Expectation.new(String, :new, :track, [], []).receiver_class)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_instance_receiver_class
|
|
47
|
-
assert_equal(String, Expectation.new(String.new, :new, :track, [], []).receiver_class)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_arg_types
|
|
51
|
-
expectation = Expectation.new(String.new, :new, :track, [:sym, "str"], [])
|
|
52
|
-
assert_equal([Symbol, String], expectation.arg_types)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def test_return_value_type
|
|
56
|
-
expectation = Expectation.new(String, :new, :track)
|
|
57
|
-
expectation.add_return_values(:sym)
|
|
58
|
-
assert_equal(Symbol, expectation.return_value_type)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_true_class_return_value_type
|
|
62
|
-
expectation = Expectation.new(String, :new, :track)
|
|
63
|
-
expectation.add_return_values(true)
|
|
64
|
-
assert_equal(TrueClass, expectation.return_value_type)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def test_false_class_return_value_type
|
|
68
|
-
expectation = Expectation.new(String, :new, :track)
|
|
69
|
-
expectation.add_return_values(false)
|
|
70
|
-
assert_equal(FalseClass, expectation.return_value_type)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_returns_nil_return_value_type_when_no_return_values
|
|
74
|
-
expectation = Expectation.new(String, :new, :track)
|
|
75
|
-
assert_nil(expectation.return_value_type)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_adds_return_value
|
|
79
|
-
expectation = Expectation.new(String.new, :new, :track, [], [:sym])
|
|
80
|
-
expectation.add_return_values("str")
|
|
81
|
-
actual = expectation.instance_variable_get(:@return_values)
|
|
82
|
-
assert_equal([:sym, "str"], actual)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def test_return_values_defined_when_return_values_added
|
|
86
|
-
expectation = Expectation.new(String.new, :new, :track, [], [:sym])
|
|
87
|
-
expectation.add_return_values("str")
|
|
88
|
-
assert(expectation.return_values_defined?)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def test_return_values_not_defined_when_no_return_values_added
|
|
92
|
-
expectation = Expectation.new(String.new, :new, :track, [], [:sym])
|
|
93
|
-
assert(!expectation.return_values_defined?)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_explodes_to_new_expectations_for_each_return_value
|
|
97
|
-
expectation = Expectation.new(String, :new, :track, [])
|
|
98
|
-
expectation.add_return_values(:sym, "str")
|
|
99
|
-
expected = [
|
|
100
|
-
Expectation.new(String, :new, :track, [], [:sym]),
|
|
101
|
-
Expectation.new(String, :new, :track, [], ["str"])
|
|
102
|
-
]
|
|
103
|
-
assert_equal(expected, expectation.explode)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def test_returns_self_when_only_one_return_type_on_explode
|
|
107
|
-
expectation = Expectation.new(String, :new, :track, [])
|
|
108
|
-
expectation.add_return_values("rock")
|
|
109
|
-
assert_equal(expectation, expectation.explode)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
data/test/synthesis/helper.rb
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class MethodInvocationWatcherTest < Test::Unit::TestCase
|
|
5
|
-
def teardown
|
|
6
|
-
ExpectationRecord.send(:reset!)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_marks_expectation_invoked
|
|
10
|
-
c = Class.new { def foo; end }
|
|
11
|
-
ExpectationRecord.add_expectation(c, :to_s, :track, []).add_return_values(1)
|
|
12
|
-
ExpectationRecord.record_invocations
|
|
13
|
-
MethodInvocationWatcher.invoked(c, :to_s, [], [1])
|
|
14
|
-
expectation = ExpectationRecord.expectations.to_a.first
|
|
15
|
-
assert(expectation.invoked?)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + "/helper"
|
|
2
|
-
|
|
3
|
-
module Synthesis
|
|
4
|
-
class RecordableTest < Test::Unit::TestCase
|
|
5
|
-
def test_redefines_method
|
|
6
|
-
foo = Class.new { def a; end }
|
|
7
|
-
foo.extend(Recordable)
|
|
8
|
-
foo.recordable_method(:a)
|
|
9
|
-
assert_respond_to(foo.new, :__recordable__a)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_records_method_invocation
|
|
13
|
-
foo = Class.new { def b; end }
|
|
14
|
-
foo.extend(Recordable)
|
|
15
|
-
foo.recordable_method(:b)
|
|
16
|
-
bar = foo.new
|
|
17
|
-
MethodInvocationWatcher.expects(:invoked).with(bar, :b, [], [nil])
|
|
18
|
-
bar.b
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_does_not_redefine_already_redefined_method
|
|
22
|
-
foo = Class.new { def b; end }
|
|
23
|
-
foo.extend(Recordable)
|
|
24
|
-
foo.stubs(:method_defined?).returns(true)
|
|
25
|
-
foo.expects(:alias_method).never
|
|
26
|
-
foo.recordable_method(:b)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_defines_non_existent_method
|
|
30
|
-
foo = Class.new
|
|
31
|
-
foo.extend(Recordable)
|
|
32
|
-
foo.recordable_method(:bar)
|
|
33
|
-
assert_respond_to(foo.new, :bar)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def test_defines_non_existent_method_recordable_placeholder_method
|
|
37
|
-
foo = Class.new
|
|
38
|
-
foo.extend(Recordable)
|
|
39
|
-
foo.recordable_method(:bar)
|
|
40
|
-
assert_respond_to(foo.new, :__recordable__bar)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_non_existed_method_placeholder_raises
|
|
44
|
-
foo = Class.new
|
|
45
|
-
foo.extend(Recordable)
|
|
46
|
-
foo.recordable_method(:bar)
|
|
47
|
-
assert_raise(RuntimeError) { foo.new.__recordable__bar }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_does_not_redefine_already_defined_magic_method
|
|
51
|
-
foo = Class.new
|
|
52
|
-
foo.extend(Recordable)
|
|
53
|
-
foo.recordable_method(:b)
|
|
54
|
-
foo.expects(:alias_method).never
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_records_magic_method_invocation
|
|
58
|
-
foo = Class.new {def method_missing(meth, *args) :magic! end}
|
|
59
|
-
foo.extend(Recordable)
|
|
60
|
-
foo.recordable_method(:b)
|
|
61
|
-
bar = foo.new
|
|
62
|
-
MethodInvocationWatcher.expects(:invoked).with(bar, :b, [], [:magic!])
|
|
63
|
-
bar.b
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def test_records_raised_exception
|
|
67
|
-
begin
|
|
68
|
-
foo = Class.new {def bar() raise end}
|
|
69
|
-
foo.extend(Recordable)
|
|
70
|
-
foo.recordable_method(:bar)
|
|
71
|
-
inst = foo.new
|
|
72
|
-
matcher = Expectation.new(inst, :bar, nil, [])
|
|
73
|
-
matcher.add_return_values(RuntimeError.new)
|
|
74
|
-
not_found = Expectation::NilExpectation.new
|
|
75
|
-
ExpectationRecord.expects(:[]).with(matcher).returns(not_found)
|
|
76
|
-
inst.bar
|
|
77
|
-
rescue => e
|
|
78
|
-
raise e unless e.is_a?(RuntimeError)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_reraises_recorded_exception
|
|
83
|
-
assert_raise(RuntimeError) do
|
|
84
|
-
foo = Class.new {def bar() raise end}
|
|
85
|
-
foo.extend(Recordable)
|
|
86
|
-
foo.recordable_method(:bar)
|
|
87
|
-
foo.new.bar
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def test_records_raised_exception_for_magic_method
|
|
92
|
-
begin
|
|
93
|
-
foo = Class.new {def method_missing(m, *a) raise end}
|
|
94
|
-
foo.extend(Recordable)
|
|
95
|
-
foo.recordable_method(:bar)
|
|
96
|
-
inst = foo.new
|
|
97
|
-
matcher = Expectation.new(inst, :bar, nil, [])
|
|
98
|
-
matcher.add_return_values(RuntimeError.new)
|
|
99
|
-
not_found = Expectation::NilExpectation.new
|
|
100
|
-
ExpectationRecord.expects(:[]).with(matcher).returns(not_found)
|
|
101
|
-
inst.bar
|
|
102
|
-
rescue => e
|
|
103
|
-
raise e unless e.is_a?(RuntimeError)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def test_reraises_recorded_exception_for_magic_method
|
|
108
|
-
assert_raise(RuntimeError) do
|
|
109
|
-
foo = Class.new {def method_missing(m, *a) raise end}
|
|
110
|
-
foo.extend(Recordable)
|
|
111
|
-
foo.recordable_method(:bar)
|
|
112
|
-
foo.new.bar
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "expectations"
|
|
3
|
-
require File.dirname(__FILE__) + "/../../test_project"
|
|
4
|
-
|
|
5
|
-
Expectations do
|
|
6
|
-
expect Storage.new('whatever').to.receive(:save).with('METAL - rock') do |storage|
|
|
7
|
-
DataBrander.new(storage).save_branded 'rock'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
expect Storage.new("").to.receive(:ouch!).raises(Problem.new) do |storage|
|
|
11
|
-
begin
|
|
12
|
-
DataBrander.new(storage).dont_do_this
|
|
13
|
-
rescue Problem
|
|
14
|
-
return true
|
|
15
|
-
end
|
|
16
|
-
fail
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "expectations"
|
|
3
|
-
require File.dirname(__FILE__) + "/../../test_project"
|
|
4
|
-
|
|
5
|
-
Expectations do
|
|
6
|
-
expect "rock" do
|
|
7
|
-
begin
|
|
8
|
-
Storage.new('test.txt').save('rock')
|
|
9
|
-
File.read 'test.txt'
|
|
10
|
-
ensure
|
|
11
|
-
FileUtils.rm_f 'test.txt'
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
expect Problem do
|
|
16
|
-
Storage.new("").ouch!
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# expect(Storage.new("").to.receive(:never_call_me).never) {}
|
|
20
|
-
|
|
21
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
%w(test/unit rubygems mocha).each { |l| require l }
|
|
2
|
-
require File.dirname(__FILE__) + "/../../test_project"
|
|
3
|
-
|
|
4
|
-
class DataBranderTest < Test::Unit::TestCase
|
|
5
|
-
def test_saves_branded_to_storage
|
|
6
|
-
storage = Storage.new 'whatever'
|
|
7
|
-
storage.expects(:save).with('METAL - rock')
|
|
8
|
-
DataBrander.new(storage).save_branded('rock')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_ignores_total_ducks
|
|
12
|
-
m = mock
|
|
13
|
-
m.expects(:foo)
|
|
14
|
-
m.foo
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_delegates_problem
|
|
18
|
-
storage = Storage.new("")
|
|
19
|
-
storage.expects(:ouch!).raises(Problem.new)
|
|
20
|
-
assert_raise(Problem) { DataBrander.new(storage).dont_do_this }
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_is_ok
|
|
24
|
-
storage = Storage.new("")
|
|
25
|
-
storage.expects(:ok_or_problem).with(:ok).returns(:ok)
|
|
26
|
-
DataBrander.new(storage).ok
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_does_not_rescue_problem_on_not_ok
|
|
30
|
-
assert_raise(Problem) do
|
|
31
|
-
storage = Storage.new("")
|
|
32
|
-
storage.expects(:ok_or_problem).with(:not_ok).raises(Problem.new)
|
|
33
|
-
DataBrander.new(storage).not_ok
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
require "test/unit"
|
|
2
|
-
require "fileutils"
|
|
3
|
-
require File.dirname(__FILE__) + "/../../test_project"
|
|
4
|
-
require "rubygems"
|
|
5
|
-
require "mocha"
|
|
6
|
-
|
|
7
|
-
class StorageTest < Test::Unit::TestCase
|
|
8
|
-
def test_saves_to_file
|
|
9
|
-
Storage.new('test.txt').save('rock')
|
|
10
|
-
assert_equal 'rock', File.read('test.txt')
|
|
11
|
-
ensure
|
|
12
|
-
FileUtils.rm_f('test.txt')
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_ouch_raises_problem
|
|
16
|
-
assert_raise(Problem) { Storage.new("").ouch! }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def test_ok_or_problem_returns_ok_when_given_ok
|
|
20
|
-
assert_equal(:ok, Storage.new("").ok_or_problem(:ok))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def test_ok_raises_problem_when_not_given_ok
|
|
24
|
-
assert_raise(Problem) { Storage.new("").ok_or_problem(:not_ok) }
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_never_called
|
|
28
|
-
storage = Storage.new("")
|
|
29
|
-
storage.expects(:never_call_me).never
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
%w(rubygems spec fileutils).each { |l| require l }
|
|
2
|
-
require File.dirname(__FILE__) + "/../test_project"
|
|
3
|
-
|
|
4
|
-
describe DataBrander do
|
|
5
|
-
it "should save branded to pstore" do
|
|
6
|
-
pstore = Storage.new 'whatever'
|
|
7
|
-
pstore.should_receive(:save).with('METAL - rock')
|
|
8
|
-
DataBrander.new(pstore).save_branded 'rock'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "should ignore total ducks" do
|
|
12
|
-
m = mock(Storage)
|
|
13
|
-
m.should_receive(:foo)
|
|
14
|
-
m.foo
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it "should delegate problem" do
|
|
18
|
-
storage = Storage.new("")
|
|
19
|
-
storage.should_receive(:ouch!).and_raise(Problem.new)
|
|
20
|
-
proc {DataBrander.new(storage).dont_do_this}.should raise_error(Problem)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should return :ok when given :ok" do
|
|
24
|
-
storage = Storage.new("")
|
|
25
|
-
storage.should_receive(:ok_or_problem).with(:ok).and_return(:ok)
|
|
26
|
-
DataBrander.new(storage).ok
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should not rescue problem on not ok" do
|
|
30
|
-
proc do
|
|
31
|
-
storage = Storage.new("")
|
|
32
|
-
storage.should_receive(:ok_or_problem).with(:not_ok).and_raise(Problem.new)
|
|
33
|
-
DataBrander.new(storage).not_ok
|
|
34
|
-
end.should raise_error(Problem)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
%w(rubygems spec fileutils).each { |l| require l }
|
|
2
|
-
require File.dirname(__FILE__) + "/../test_project"
|
|
3
|
-
|
|
4
|
-
describe Storage do
|
|
5
|
-
it "should save to file" do
|
|
6
|
-
begin
|
|
7
|
-
Storage.new('test.txt').save('rock')
|
|
8
|
-
File.read('test.txt').should == 'rock'
|
|
9
|
-
ensure
|
|
10
|
-
FileUtils.rm_f('test.txt')
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should raise problem on ouch!" do
|
|
15
|
-
proc { Storage.new("").ouch! }.should raise_error(Problem)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should return :ok when given :ok" do
|
|
19
|
-
Storage.new("").ok_or_problem(:ok).should == :ok
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should raise problem when not give :ok" do
|
|
23
|
-
proc { Storage.new("").ok_or_problem(:not_ok) }.should raise_error(Problem)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should never call" do
|
|
27
|
-
storage = Storage.new("")
|
|
28
|
-
storage.should_receive(:never_call_me).never
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
class DataBrander
|
|
2
|
-
BRAND = "METAL"
|
|
3
|
-
|
|
4
|
-
def initialize(storage)
|
|
5
|
-
@storage = storage
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def save_branded(data)
|
|
9
|
-
@storage.save "#{BRAND} - #{data}"
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def dont_do_this
|
|
13
|
-
@storage.ouch!
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def ok
|
|
17
|
-
@storage.ok_or_problem(:ok)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def not_ok
|
|
21
|
-
@storage.ok_or_problem(:not_ok)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class Storage
|
|
26
|
-
def initialize(filename)
|
|
27
|
-
@filename = filename
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def save(val)
|
|
31
|
-
File.open(@filename, 'w') {|f| f << val}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def ouch!
|
|
35
|
-
raise Problem
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def ok_or_problem(ok)
|
|
39
|
-
ok == :ok ? ok : raise(Problem)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def never_call_me
|
|
43
|
-
:whatever
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
class Problem < Exception;end
|