hardmock 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -0
- data/LICENSE +7 -0
- data/README +48 -0
- data/Rakefile +93 -0
- data/lib/hardmock.rb +634 -0
- data/lib/method_cleanout.rb +14 -0
- data/test/functional/assert_error_test.rb +52 -0
- data/test/functional/auto_verify_test.rb +192 -0
- data/test/functional/direct_mock_usage_test.rb +396 -0
- data/test/functional/hardmock_test.rb +371 -0
- data/test/test_helper.rb +23 -0
- data/test/unit/expectation_builder_test.rb +18 -0
- data/test/unit/expector_test.rb +54 -0
- data/test/unit/method_cleanout_test.rb +35 -0
- data/test/unit/mock_control_test.rb +172 -0
- data/test/unit/mock_test.rb +275 -0
- data/test/unit/simple_expectation_test.rb +345 -0
- data/test/unit/trapper_test.rb +60 -0
- data/test/unit/verify_error_test.rb +34 -0
- metadata +81 -0
data/CHANGES
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Hardmock 1.0.3
|
2
|
+
|
3
|
+
* "expects" replaces "expect" ("expect" now raises Hardmock::DeprecationError)
|
4
|
+
* "verify_mocks" is now implicit in teardown, you needn't call it anymore
|
5
|
+
* Mocking methods that Mock would otherwise inherit from Object (eg, to_s) is now possible
|
6
|
+
* require 'hardmock' is all that's required to use the library now; no need to include in TestCase
|
7
|
+
|
8
|
+
(previously called CMock, translated to Hardmock on 2006-12-10)
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2006 Atomic Object, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
== Hardmock
|
2
|
+
|
3
|
+
Strict, ordered mock objects using very lightweight syntax in your tests.
|
4
|
+
|
5
|
+
|
6
|
+
== How
|
7
|
+
|
8
|
+
The basic procedure for using Hardmock in your tests is:
|
9
|
+
|
10
|
+
* require 'hardmock'
|
11
|
+
* Create some mocks
|
12
|
+
* Setup some expectations
|
13
|
+
* Execute the target code
|
14
|
+
* Verification of calls is automatic in =teardown=
|
15
|
+
|
16
|
+
The expectations you set when using mocks are <b>strict</b> and <b>ordered</b>.
|
17
|
+
Expectations you declare by creating and using mocks are all considered together.
|
18
|
+
|
19
|
+
* Hardmock::Mock#expects will show you more examples
|
20
|
+
* Hardmock::SimpleExpectation will teach you more about expectation methods
|
21
|
+
|
22
|
+
== Example
|
23
|
+
|
24
|
+
create_mocks :garage, :car
|
25
|
+
|
26
|
+
# Set some expectations
|
27
|
+
@garage.expects.open_door
|
28
|
+
@car.expects.start(:choke)
|
29
|
+
@car.expects.drive(:reverse, 5.mph)
|
30
|
+
|
31
|
+
# Execute the code (this code is usually, obviously, in your class under test)
|
32
|
+
@garage.open_door
|
33
|
+
@car.start :choke
|
34
|
+
@car.drive :reverse, 5.mph
|
35
|
+
|
36
|
+
verify_mocks # OPTIONAL, teardown will do this for you
|
37
|
+
|
38
|
+
Expects <tt>@garage.open_door</tt>, <tt>@car.start(:choke)</tt> and <tt>@car.drive(:reverse, 5.mph)</tt> to be called in that order, with those specific arguments.
|
39
|
+
* Violations of expectations, such as mis-ordered calls, calls on wrong objects, or incorrect methods result in Hardmock::ExpectationError
|
40
|
+
* <tt>verify_mocks</tt> will raise VerifyError if not all expectations have been met.
|
41
|
+
|
42
|
+
== Download and Install
|
43
|
+
|
44
|
+
* Homepage: http://hardmock.rubyforge.org
|
45
|
+
* GEM or TGZ or ZIP: http://rubyforge.org/frs/?group_id=2742
|
46
|
+
* Rails plugin: script/plugin install
|
47
|
+
* SVN access: svn co svn://rubyforge.org/var/svn/hardmock/trunk
|
48
|
+
* Developer SVN access: svn co svn://developername@rubyforge.org/var/svn/hardmock/trunk
|
data/Rakefile
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
require 'rake/contrib/sshpublisher'
|
7
|
+
|
8
|
+
HARDMOCK_VERSION = "1.1.0"
|
9
|
+
|
10
|
+
task :default => [ :alltests ]
|
11
|
+
|
12
|
+
desc "Run all the tests"
|
13
|
+
Rake::TestTask.new("alltests") { |t|
|
14
|
+
t.libs << "test"
|
15
|
+
t.pattern = 'test/**/*_test.rb'
|
16
|
+
t.verbose = true
|
17
|
+
}
|
18
|
+
|
19
|
+
def add_rdoc_options(options)
|
20
|
+
options << '--line-numbers' << '--inline-source' << '--main' << 'README' << '--title' << 'Hardmock'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Generate RDoc documentation"
|
24
|
+
Rake::RDocTask.new { |rdoc|
|
25
|
+
rdoc.rdoc_dir = 'doc'
|
26
|
+
rdoc.title = "Hardmock: Strict expectation-based mock object library "
|
27
|
+
# rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object' << '--main'
|
28
|
+
add_rdoc_options(rdoc.options)
|
29
|
+
rdoc.rdoc_files.include('lib/**/*.rb', 'README','CHANGES','LICENSE')
|
30
|
+
}
|
31
|
+
|
32
|
+
task :showdoc => [ :rerdoc ] do
|
33
|
+
sh "open doc/index.html"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Generate and upload api docs to rubyforge"
|
37
|
+
task :upload_doc => :rerdoc do
|
38
|
+
sh "scp -r doc/* rubyforge.org:/var/www/gforge-projects/hardmock/doc"
|
39
|
+
sh "scp -r homepage/* rubyforge.org:/var/www/gforge-projects/hardmock/"
|
40
|
+
end
|
41
|
+
|
42
|
+
gem_spec = Gem::Specification.new do | s |
|
43
|
+
s.name = "hardmock"
|
44
|
+
s.version = HARDMOCK_VERSION
|
45
|
+
s.author = "David Crosby"
|
46
|
+
s.email = "crosby@atomicobject.com"
|
47
|
+
s.platform = Gem::Platform::RUBY
|
48
|
+
s.summary = "A strict, ordered, expectation-oriented mock object library."
|
49
|
+
s.rubyforge_project = 'hardmock'
|
50
|
+
s.homepage = "http://hardmock.rubyforge.org"
|
51
|
+
s.autorequire = 'hardmock'
|
52
|
+
|
53
|
+
|
54
|
+
s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
|
55
|
+
|
56
|
+
s.require_path = "lib"
|
57
|
+
s.test_files = Dir.glob("test/**/*test.rb")
|
58
|
+
|
59
|
+
s.has_rdoc = true
|
60
|
+
s.extra_rdoc_files = ["README","CHANGES","LICENSE"]
|
61
|
+
# s.rdoc_options << '--title' << 'Harmock' << '--main' << 'README' << '--line-numbers'
|
62
|
+
add_rdoc_options(s.rdoc_options)
|
63
|
+
end
|
64
|
+
|
65
|
+
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
66
|
+
pkg.need_zip = true
|
67
|
+
pkg.need_tar = true
|
68
|
+
end
|
69
|
+
|
70
|
+
task :verify_svn_clean do
|
71
|
+
# Get clean
|
72
|
+
sh 'svn up'
|
73
|
+
status = `svn status`
|
74
|
+
raise "Please get checked-in and cleaned up before releasing.\n#{status}" unless status == ""
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "Create a release tar.gz file."
|
78
|
+
task :release => [:verify_svn_clean, :alltests, :upload_doc, :repackage] do
|
79
|
+
require 'fileutils'
|
80
|
+
include FileUtils::Verbose
|
81
|
+
proj_root = File.expand_path(File.dirname(__FILE__))
|
82
|
+
begin
|
83
|
+
cd proj_root
|
84
|
+
|
85
|
+
|
86
|
+
# Tag the release by number, then re-tag for stable release (makes nicey nicey for Rails plugin installation)
|
87
|
+
sh "svn cp . svn+ssh://dcrosby42@rubyforge.org/var/svn/hardmock/tags/rel-#{HARDMOCK_VERSION} -m 'Releasing version #{HARDMOCK_VERSION}'"
|
88
|
+
sh "svn del svn+ssh://dcrosby42@rubyforge.org/var/svn/hardmock/tags/hardmock -m 'Preparing to update stable release tag'"
|
89
|
+
sh "svn cp . svn+ssh://dcrosby42@rubyforge.org/var/svn/hardmock/tags/hardmock -m 'Updating stable tag to version #{HARDMOCK_VERSION}'"
|
90
|
+
|
91
|
+
puts "UPLOAD #{Dir['pkg/*.*']} TO RUBYFORGE RELEASE ZONE"
|
92
|
+
end
|
93
|
+
end
|