gimme 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/Gemfile +13 -4
- data/Gemfile.lock +50 -21
- data/Guardfile +15 -0
- data/README.markdown +2 -2
- data/Rakefile +12 -9
- data/VERSION +1 -1
- data/features/step_definitions/gimme_steps.rb +1 -1
- data/gimme.gemspec +53 -17
- data/lib/gimme/matchers.rb +1 -1
- data/lib/gimme/rspec_adapter.rb +12 -0
- data/lib/gimme/verifies.rb +10 -1
- data/lib/gimme.rb +3 -1
- data/spec/gimme/captor_spec.rb +34 -0
- data/spec/gimme/errors_spec.rb +5 -0
- data/spec/gimme/gives_spec.rb +52 -0
- data/spec/gimme/matchers_spec.rb +125 -0
- data/spec/gimme/test_double_spec.rb +25 -0
- data/spec/gimme/verifies_spec.rb +120 -0
- data/spec/spec_helper.rb +11 -0
- metadata +157 -117
- data/.bundle/config +0 -2
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -3,9 +3,18 @@ source "http://rubygems.org"
|
|
3
3
|
|
4
4
|
# Add dependencies to develop your gem here.
|
5
5
|
# Include everything needed to run rake, tests, features, etc.
|
6
|
-
group :development do
|
7
|
-
gem
|
6
|
+
group :development, :test do
|
7
|
+
gem 'rdoc'
|
8
|
+
|
8
9
|
gem "jeweler", "~> 1.5.2"
|
9
|
-
gem "rspec"
|
10
|
-
gem "
|
10
|
+
gem "rspec"
|
11
|
+
gem "rspec-given"
|
12
|
+
gem "guard-rspec", :require => false
|
13
|
+
gem "cucumber"
|
14
|
+
gem "guard-cucumber", :require => false
|
15
|
+
gem "simplecov", :require => false
|
16
|
+
if RUBY_PLATFORM =~ /darwin/i
|
17
|
+
gem "growl_notify"
|
18
|
+
gem "rb-fsevent", :require => false
|
19
|
+
end
|
11
20
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,37 +2,66 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
builder (3.0.0)
|
5
|
-
cucumber (
|
5
|
+
cucumber (1.1.9)
|
6
6
|
builder (>= 2.1.2)
|
7
|
-
diff-lcs (
|
8
|
-
gherkin (~> 2.
|
9
|
-
json (
|
10
|
-
term-ansicolor (
|
11
|
-
diff-lcs (1.1.
|
12
|
-
|
13
|
-
|
7
|
+
diff-lcs (>= 1.1.2)
|
8
|
+
gherkin (~> 2.9.0)
|
9
|
+
json (>= 1.4.6)
|
10
|
+
term-ansicolor (>= 1.0.6)
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
ffi (1.0.11)
|
13
|
+
gherkin (2.9.0)
|
14
|
+
json (>= 1.4.6)
|
14
15
|
git (1.2.5)
|
16
|
+
growl_notify (0.0.3)
|
17
|
+
rb-appscript
|
18
|
+
guard (1.0.0)
|
19
|
+
ffi (>= 0.5.0)
|
20
|
+
thor (~> 0.14.6)
|
21
|
+
guard-cucumber (0.7.5)
|
22
|
+
cucumber (>= 0.10)
|
23
|
+
guard (>= 0.8.3)
|
24
|
+
guard-rspec (0.6.0)
|
25
|
+
guard (>= 0.10.0)
|
15
26
|
jeweler (1.5.2)
|
16
27
|
bundler (~> 1.0.0)
|
17
28
|
git (>= 1.2.5)
|
18
29
|
rake
|
19
|
-
json (1.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rspec
|
30
|
+
json (1.6.5)
|
31
|
+
multi_json (1.1.0)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rb-appscript (0.6.1)
|
34
|
+
rb-fsevent (0.9.0)
|
35
|
+
rdoc (3.12)
|
36
|
+
json (~> 1.4)
|
37
|
+
rspec (2.8.0)
|
38
|
+
rspec-core (~> 2.8.0)
|
39
|
+
rspec-expectations (~> 2.8.0)
|
40
|
+
rspec-mocks (~> 2.8.0)
|
41
|
+
rspec-core (2.8.0)
|
42
|
+
rspec-expectations (2.8.0)
|
27
43
|
diff-lcs (~> 1.1.2)
|
28
|
-
rspec-
|
29
|
-
|
44
|
+
rspec-given (1.4.2)
|
45
|
+
rspec (> 1.2.8)
|
46
|
+
rspec-mocks (2.8.0)
|
47
|
+
simplecov (0.6.1)
|
48
|
+
multi_json (~> 1.0)
|
49
|
+
simplecov-html (~> 0.5.3)
|
50
|
+
simplecov-html (0.5.3)
|
51
|
+
term-ansicolor (1.0.7)
|
52
|
+
thor (0.14.6)
|
30
53
|
|
31
54
|
PLATFORMS
|
32
55
|
ruby
|
33
56
|
|
34
57
|
DEPENDENCIES
|
35
|
-
|
36
|
-
|
58
|
+
cucumber
|
59
|
+
growl_notify
|
60
|
+
guard-cucumber
|
61
|
+
guard-rspec
|
37
62
|
jeweler (~> 1.5.2)
|
38
|
-
|
63
|
+
rb-fsevent
|
64
|
+
rdoc
|
65
|
+
rspec
|
66
|
+
rspec-given
|
67
|
+
simplecov
|
data/Guardfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :cli => '--color', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
guard 'cucumber' do
|
12
|
+
watch(%r{^features/.+\.feature$})
|
13
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
14
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
15
|
+
end
|
data/README.markdown
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Gimme
|
2
2
|
|
3
|
-
Gimme is a very lightweight test double library for ruby. Written to be an opinionated (but not noisy) means to facilitate test-driving by enabling the author to
|
3
|
+
Gimme is a very lightweight test double library for ruby. Written to be an opinionated (but not noisy) means to facilitate test-driving by enabling the author to specify only what she cares about. If I could only feed Google one thing at this point, it would be: "[Mockito](http://mockito.org/) for Ruby"
|
4
4
|
|
5
5
|
You can read the (possibly stale) documentation below or the (fresh) [gimme Cucumber features on Relish](http://relishapp.com/searls/gimme)
|
6
6
|
|
7
|
-
And here's a [blog post outlining the case for gimme](http://
|
7
|
+
And here's a [blog post outlining the case for gimme](http://searls.test-double.com/2011/06/03/whats-wrong-with-rubys-test-doubles/).
|
8
8
|
|
9
9
|
## Basics (or "What does it Gimme?" ... har.)
|
10
10
|
|
data/Rakefile
CHANGED
@@ -28,15 +28,8 @@ Jeweler::Tasks.new do |gem|
|
|
28
28
|
end
|
29
29
|
Jeweler::RubygemsDotOrgTasks.new
|
30
30
|
|
31
|
-
require '
|
32
|
-
|
33
|
-
t.cucumber_opts = %w{--format pretty}
|
34
|
-
end
|
35
|
-
|
36
|
-
task :default => :cucumber
|
37
|
-
|
38
|
-
require 'rake/rdoctask'
|
39
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
+
require 'rdoc/task'
|
32
|
+
RDoc::Task.new do |rdoc|
|
40
33
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
34
|
|
42
35
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -44,3 +37,13 @@ Rake::RDocTask.new do |rdoc|
|
|
44
37
|
rdoc.rdoc_files.include('README*')
|
45
38
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
39
|
end
|
40
|
+
|
41
|
+
require 'cucumber/rake/task'
|
42
|
+
Cucumber::Rake::Task.new do |t|
|
43
|
+
t.cucumber_opts = %w{--format progress}
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'rspec/core/rake_task'
|
47
|
+
RSpec::Core::RakeTask.new
|
48
|
+
|
49
|
+
task :default => [:spec,:cucumber]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/gimme.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gimme}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{
|
11
|
+
s.authors = [%q{Justin Searls}]
|
12
|
+
s.date = %q{2012-02-25}
|
13
13
|
s.description = %q{gimme attempts to bring to Ruby a test double workflow akin to Mockito in Java. Major distinctions include preserving arrange-act-assert in tests, fast feedback for methods the double's real counterpart may not know how to respond to, no string/symbolic representations of methods, argument captors, and strong opinions (weakly held). }
|
14
14
|
s.email = %q{searls@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,10 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
"README.rdoc"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
".bundle/config",
|
22
21
|
".document",
|
22
|
+
".travis.yml",
|
23
23
|
"Gemfile",
|
24
24
|
"Gemfile.lock",
|
25
|
+
"Guardfile",
|
25
26
|
"LICENSE.txt",
|
26
27
|
"README.markdown",
|
27
28
|
"README.rdoc",
|
@@ -47,38 +48,73 @@ Gem::Specification.new do |s|
|
|
47
48
|
"lib/gimme/gives.rb",
|
48
49
|
"lib/gimme/matchers.rb",
|
49
50
|
"lib/gimme/method_resolver.rb",
|
51
|
+
"lib/gimme/rspec_adapter.rb",
|
50
52
|
"lib/gimme/test_double.rb",
|
51
|
-
"lib/gimme/verifies.rb"
|
53
|
+
"lib/gimme/verifies.rb",
|
54
|
+
"spec/gimme/captor_spec.rb",
|
55
|
+
"spec/gimme/errors_spec.rb",
|
56
|
+
"spec/gimme/gives_spec.rb",
|
57
|
+
"spec/gimme/matchers_spec.rb",
|
58
|
+
"spec/gimme/test_double_spec.rb",
|
59
|
+
"spec/gimme/verifies_spec.rb",
|
60
|
+
"spec/spec_helper.rb"
|
52
61
|
]
|
53
62
|
s.homepage = %q{http://github.com/searls/gimme}
|
54
|
-
s.licenses = [
|
55
|
-
s.require_paths = [
|
56
|
-
s.rubygems_version = %q{1.
|
63
|
+
s.licenses = [%q{MIT}]
|
64
|
+
s.require_paths = [%q{lib}]
|
65
|
+
s.rubygems_version = %q{1.8.6}
|
57
66
|
s.summary = %q{gimme — a low-specification test double library for Ruby}
|
67
|
+
s.test_files = [
|
68
|
+
"spec/gimme/captor_spec.rb",
|
69
|
+
"spec/gimme/errors_spec.rb",
|
70
|
+
"spec/gimme/gives_spec.rb",
|
71
|
+
"spec/gimme/matchers_spec.rb",
|
72
|
+
"spec/gimme/test_double_spec.rb",
|
73
|
+
"spec/gimme/verifies_spec.rb",
|
74
|
+
"spec/spec_helper.rb"
|
75
|
+
]
|
58
76
|
|
59
77
|
if s.respond_to? :specification_version then
|
60
78
|
s.specification_version = 3
|
61
79
|
|
62
80
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
-
s.add_development_dependency(%q<
|
81
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
64
82
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
-
s.add_development_dependency(%q<rspec>, [">=
|
66
|
-
s.add_development_dependency(%q<
|
83
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
84
|
+
s.add_development_dependency(%q<rspec-given>, [">= 0"])
|
85
|
+
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
86
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
87
|
+
s.add_development_dependency(%q<guard-cucumber>, [">= 0"])
|
88
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
89
|
+
s.add_development_dependency(%q<growl_notify>, [">= 0"])
|
90
|
+
s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
|
67
91
|
s.add_development_dependency(%q<rspec>, [">= 1.3.1"])
|
68
92
|
s.add_development_dependency(%q<cucumber>, [">= 0.10.0"])
|
69
93
|
else
|
70
|
-
s.add_dependency(%q<
|
94
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
71
95
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
72
|
-
s.add_dependency(%q<rspec>, [">=
|
73
|
-
s.add_dependency(%q<
|
96
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
97
|
+
s.add_dependency(%q<rspec-given>, [">= 0"])
|
98
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
99
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
100
|
+
s.add_dependency(%q<guard-cucumber>, [">= 0"])
|
101
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
102
|
+
s.add_dependency(%q<growl_notify>, [">= 0"])
|
103
|
+
s.add_dependency(%q<rb-fsevent>, [">= 0"])
|
74
104
|
s.add_dependency(%q<rspec>, [">= 1.3.1"])
|
75
105
|
s.add_dependency(%q<cucumber>, [">= 0.10.0"])
|
76
106
|
end
|
77
107
|
else
|
78
|
-
s.add_dependency(%q<
|
108
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
79
109
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
|
-
s.add_dependency(%q<rspec>, [">=
|
81
|
-
s.add_dependency(%q<
|
110
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
111
|
+
s.add_dependency(%q<rspec-given>, [">= 0"])
|
112
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
113
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
114
|
+
s.add_dependency(%q<guard-cucumber>, [">= 0"])
|
115
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
116
|
+
s.add_dependency(%q<growl_notify>, [">= 0"])
|
117
|
+
s.add_dependency(%q<rb-fsevent>, [">= 0"])
|
82
118
|
s.add_dependency(%q<rspec>, [">= 1.3.1"])
|
83
119
|
s.add_dependency(%q<cucumber>, [">= 0.10.0"])
|
84
120
|
end
|
data/lib/gimme/matchers.rb
CHANGED
data/lib/gimme/verifies.rb
CHANGED
@@ -27,7 +27,16 @@ module Gimme
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if invoked != @times
|
30
|
-
|
30
|
+
msg = "expected #{@double.cls.to_s}##{sym} to have been called with arguments #{args}"
|
31
|
+
if !@double.invocations[sym] || @double.invocations[sym].empty?
|
32
|
+
msg << "\n but was never called"
|
33
|
+
else
|
34
|
+
msg = @double.invocations[sym].inject msg do |memo, actual|
|
35
|
+
memo + "\n was actually called #{actual[1]} times with arguments #{actual[0]}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
raise Errors::VerificationFailedError.new(msg)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
end
|
data/lib/gimme.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe Gimme::Captor do
|
5
|
+
describe "#value" do
|
6
|
+
Given(:captor) { Captor.new }
|
7
|
+
When { captor.value = "panda" }
|
8
|
+
Then { captor.value.should == "panda" }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Gimme::Matchers::Capture do
|
13
|
+
Given(:captor) { Captor.new }
|
14
|
+
|
15
|
+
shared_examples_for "an argument captor" do
|
16
|
+
describe "#matches?" do
|
17
|
+
When(:result) { a_capture.matches?("anything at all") }
|
18
|
+
Then { result.should == true }
|
19
|
+
Then { captor.value.should == "anything at all" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "using the class API" do
|
24
|
+
it_behaves_like "an argument captor" do
|
25
|
+
Given(:a_capture) { Capture.new(captor) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "using gimme DSL" do
|
30
|
+
it_behaves_like "an argument captor" do
|
31
|
+
Given(:a_capture) { capture(captor) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gimme::Gives do
|
4
|
+
class Bunny
|
5
|
+
def nibble
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
shared_examples_for "a normal stubbing" do
|
10
|
+
context "stubbing an existing method" do
|
11
|
+
When { gives.nibble() { "nom" } }
|
12
|
+
Then { subject.nibble.should == "nom" }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "stubbing a non-existent method" do
|
16
|
+
When(:stubbing) { lambda { gives.bark { "woof" } } }
|
17
|
+
Then { stubbing.should raise_error NoMethodError }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
shared_examples_for "an overridden stubbing" do
|
22
|
+
context "configured to _not_ raise an error when stubbed method does not exist" do
|
23
|
+
Given { gives.raises_no_method_error =false }
|
24
|
+
When { gives.bark { "woof" } }
|
25
|
+
Then { subject.bark.should == "woof" }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "using the class API" do
|
30
|
+
Given(:subject) { TestDouble.new(Bunny) }
|
31
|
+
|
32
|
+
it_behaves_like "a normal stubbing" do
|
33
|
+
Given(:gives) { Gives.new(subject) }
|
34
|
+
end
|
35
|
+
|
36
|
+
it_behaves_like "an overridden stubbing" do
|
37
|
+
Given(:gives) { Gives.new(subject) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "using the gimme DSL" do
|
42
|
+
Given(:subject) { gimme(Bunny) }
|
43
|
+
|
44
|
+
it_behaves_like "a normal stubbing" do
|
45
|
+
Given(:gives) { give(subject) }
|
46
|
+
end
|
47
|
+
|
48
|
+
it_behaves_like "an overridden stubbing" do
|
49
|
+
Given(:gives) { give!(subject) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :match do |expected|
|
4
|
+
match do |actual|
|
5
|
+
actual.matches?(expected)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Gimme::Matchers do
|
10
|
+
class Shoopuf
|
11
|
+
end
|
12
|
+
|
13
|
+
class BabyShoopuf < Shoopuf
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Matcher do
|
17
|
+
context "a plain, default matcher" do
|
18
|
+
Given(:matcher) { Gimme::Matchers::Matcher.new }
|
19
|
+
Then { matcher.should_not match "anything" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Anything do
|
24
|
+
shared_examples_for "an anything matcher" do
|
25
|
+
Then { matcher.should match "anything" }
|
26
|
+
end
|
27
|
+
|
28
|
+
context "class API" do
|
29
|
+
it_behaves_like "an anything matcher" do
|
30
|
+
Given(:matcher) { Anything.new }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "gimme DSL" do
|
35
|
+
it_behaves_like "an anything matcher" do
|
36
|
+
Given(:matcher) { anything }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
shared_examples_for "an identity matcher" do
|
42
|
+
Then { matcher.should match Shoopuf.new }
|
43
|
+
Then { matcher.should match BabyShoopuf.new }
|
44
|
+
end
|
45
|
+
|
46
|
+
shared_examples_for "a restrictive matcher" do
|
47
|
+
Then { matcher.should_not match nil }
|
48
|
+
Then { matcher.should_not match "Pandas" }
|
49
|
+
Then { matcher.should_not match Object.new }
|
50
|
+
Then { matcher.should_not match Class }
|
51
|
+
end
|
52
|
+
|
53
|
+
shared_examples_for "a relaxed matcher" do
|
54
|
+
Then { matcher.should match nil }
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
describe IsA do
|
59
|
+
context "class API" do
|
60
|
+
Given(:matcher) { IsA.new(Shoopuf) }
|
61
|
+
it_behaves_like "an identity matcher"
|
62
|
+
it_behaves_like "a restrictive matcher"
|
63
|
+
end
|
64
|
+
|
65
|
+
context "gimme DSL" do
|
66
|
+
Given(:matcher) { is_a(Shoopuf) }
|
67
|
+
it_behaves_like "an identity matcher"
|
68
|
+
it_behaves_like "a restrictive matcher"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Any do
|
73
|
+
context "class API" do
|
74
|
+
Given(:matcher) { Any.new(Shoopuf) }
|
75
|
+
it_behaves_like "an identity matcher"
|
76
|
+
it_behaves_like "a relaxed matcher"
|
77
|
+
end
|
78
|
+
|
79
|
+
context "gimme DSL" do
|
80
|
+
Given(:matcher) { any(Shoopuf) }
|
81
|
+
it_behaves_like "an identity matcher"
|
82
|
+
it_behaves_like "a relaxed matcher"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe Gimme::Matchers::Numeric do
|
87
|
+
shared_examples_for "a numeric matcher" do
|
88
|
+
Then { matcher.should match 5 }
|
89
|
+
Then { matcher.should match 5.5 }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "class API" do
|
93
|
+
Given(:matcher) { Gimme::Matchers::Numeric.new }
|
94
|
+
it_behaves_like "a numeric matcher"
|
95
|
+
it_behaves_like "a restrictive matcher"
|
96
|
+
end
|
97
|
+
|
98
|
+
context "gimme DSL" do
|
99
|
+
Given(:matcher) { numeric }
|
100
|
+
it_behaves_like "a numeric matcher"
|
101
|
+
it_behaves_like "a restrictive matcher"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe Gimme::Matchers::Boolean do
|
106
|
+
shared_examples_for "a boolean matcher" do
|
107
|
+
Then { matcher.should match true }
|
108
|
+
Then { matcher.should match false }
|
109
|
+
Then { matcher.should_not match Boolean }
|
110
|
+
end
|
111
|
+
|
112
|
+
context "class API" do
|
113
|
+
Given(:matcher) { Gimme::Matchers::Boolean.new }
|
114
|
+
it_behaves_like "a boolean matcher"
|
115
|
+
it_behaves_like "a restrictive matcher"
|
116
|
+
end
|
117
|
+
|
118
|
+
context "gimme DSL" do
|
119
|
+
Given(:matcher) { boolean }
|
120
|
+
it_behaves_like "a boolean matcher"
|
121
|
+
it_behaves_like "a restrictive matcher"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gimme::TestDouble do
|
4
|
+
class MassiveDamage
|
5
|
+
def boom
|
6
|
+
:asplode
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#gimme_next" do
|
11
|
+
Given(:test_double) { gimme_next(MassiveDamage) }
|
12
|
+
Given(:subject) { MassiveDamage.new }
|
13
|
+
|
14
|
+
Given { give(test_double).boom { :kaboom } }
|
15
|
+
When(:result) { subject.boom }
|
16
|
+
Then { result.should == :kaboom }
|
17
|
+
|
18
|
+
context "subsequent uses" do
|
19
|
+
Given(:next_subject) { MassiveDamage.new }
|
20
|
+
When(:next_result) { next_subject.boom }
|
21
|
+
Then { next_result.should == :asplode }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Gimme::Verifies do
|
4
|
+
class Natto
|
5
|
+
def ferment(beans=nil,time=nil)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
Given(:test_double) { gimme(Natto) }
|
9
|
+
|
10
|
+
shared_examples_for "a verifier" do
|
11
|
+
|
12
|
+
context "invoked once when expected once" do
|
13
|
+
Given { test_double.ferment }
|
14
|
+
When(:result) { lambda { verifier.ferment } }
|
15
|
+
Then { result.should_not raise_error }
|
16
|
+
end
|
17
|
+
|
18
|
+
context "never invoked" do
|
19
|
+
When(:result) { lambda { verifier.ferment } }
|
20
|
+
Then { result.should raise_error Errors::VerificationFailedError }
|
21
|
+
Then do result.should raise_error Errors::VerificationFailedError,
|
22
|
+
"expected Natto#ferment to have been called with arguments #{[]}\n"+
|
23
|
+
" but was never called"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "invoked with incorrect args" do
|
28
|
+
Given { test_double.ferment(5) }
|
29
|
+
When(:result) { lambda { verifier.ferment(4) } }
|
30
|
+
Then do result.should raise_error Errors::VerificationFailedError,
|
31
|
+
"expected Natto#ferment to have been called with arguments #{[4]}\n"+
|
32
|
+
" was actually called 1 times with arguments #{[5]}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "invoked incorrectly a whole bunch" do
|
37
|
+
Given { test_double.ferment(5) }
|
38
|
+
Given { test_double.ferment(5) }
|
39
|
+
Given { test_double.ferment(3) }
|
40
|
+
When(:result) { lambda { verifier.ferment(4) } }
|
41
|
+
Then do result.should raise_error Errors::VerificationFailedError,
|
42
|
+
/.* was actually called 2 times with arguments #{Regexp.escape([5].to_s)}.*/m
|
43
|
+
end
|
44
|
+
Then do result.should raise_error Errors::VerificationFailedError,
|
45
|
+
/.* was actually called 1 times with arguments #{Regexp.escape([3].to_s)}.*/m
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "invoked too few times" do
|
50
|
+
Given(:verifier) { Verifies.new(test_double,3) }
|
51
|
+
Given { 2.times { test_double.ferment } }
|
52
|
+
When(:result) { lambda { verifier.ferment } }
|
53
|
+
Then { result.should raise_error Errors::VerificationFailedError }
|
54
|
+
end
|
55
|
+
|
56
|
+
context "juggling multiple verifiers for the same method" do
|
57
|
+
Given(:multi_verifier) { Verifies.new(test_double,2) }
|
58
|
+
Given { test_double.ferment(:panda,:sauce) }
|
59
|
+
Given { 2.times { test_double.ferment(2,3) } }
|
60
|
+
When(:result) do
|
61
|
+
lambda do
|
62
|
+
multi_verifier.ferment(2,3)
|
63
|
+
verifier.ferment(:panda,:sauce)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
Then { result.should_not raise_error }
|
67
|
+
end
|
68
|
+
|
69
|
+
context "a method not on the test_double" do
|
70
|
+
When(:result) { lambda { verifier.eat } }
|
71
|
+
Then { result.should raise_error NoMethodError }
|
72
|
+
end
|
73
|
+
|
74
|
+
context "a satisfied argument matcher" do
|
75
|
+
Given { test_double.ferment(5) }
|
76
|
+
When(:result) { lambda { verifier.ferment(numeric) } }
|
77
|
+
Then { result.should_not raise_error }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "an unsatisifed argument matcher" do
|
81
|
+
Given { test_double.ferment("True") }
|
82
|
+
When(:result) { lambda { verifier.ferment(boolean) } }
|
83
|
+
Then { result.should raise_error Errors::VerificationFailedError }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
shared_examples_for "an overridden verifier" do
|
88
|
+
context "a method not on the double that is invoked" do
|
89
|
+
Given { test_double.eat }
|
90
|
+
When(:result) { lambda { verifier.eat } }
|
91
|
+
Then { result.should_not raise_error }
|
92
|
+
end
|
93
|
+
|
94
|
+
context "a method not on the test_double that is _not_ invoked" do
|
95
|
+
When(:result) { lambda { verifier.eat } }
|
96
|
+
Then { result.should raise_error Errors::VerificationFailedError }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "class API" do
|
101
|
+
Given(:verifier) { Verifies.new(test_double) }
|
102
|
+
it_behaves_like "a verifier"
|
103
|
+
it_behaves_like "an overridden verifier" do
|
104
|
+
Given { verifier.raises_no_method_error = false }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "gimme DSL" do
|
109
|
+
it_behaves_like "a verifier" do
|
110
|
+
Given(:verifier) { verify(test_double) }
|
111
|
+
end
|
112
|
+
|
113
|
+
it_behaves_like "an overridden verifier" do
|
114
|
+
Given(:verifier) { verify!(test_double) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,134 +1,166 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: gimme
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 7
|
10
|
-
version: 0.1.7
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Justin Searls
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2012-02-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rdoc
|
16
|
+
requirement: &903369690 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 1
|
31
|
-
- 0
|
32
|
-
- 0
|
33
|
-
version: 1.0.0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
34
22
|
type: :development
|
35
|
-
requirement: *id001
|
36
|
-
name: bundler
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
23
|
prerelease: false
|
39
|
-
version_requirements:
|
24
|
+
version_requirements: *903369690
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: jeweler
|
27
|
+
requirement: &903369430 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
|
-
requirements:
|
29
|
+
requirements:
|
42
30
|
- - ~>
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 7
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 5
|
48
|
-
- 2
|
31
|
+
- !ruby/object:Gem::Version
|
49
32
|
version: 1.5.2
|
50
33
|
type: :development
|
51
|
-
requirement: *id002
|
52
|
-
name: jeweler
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
34
|
prerelease: false
|
55
|
-
version_requirements:
|
35
|
+
version_requirements: *903369430
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &903369160 !ruby/object:Gem::Requirement
|
56
39
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 1
|
63
|
-
- 3
|
64
|
-
- 1
|
65
|
-
version: 1.3.1
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
66
44
|
type: :development
|
67
|
-
requirement: *id003
|
68
|
-
name: rspec
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
45
|
prerelease: false
|
71
|
-
version_requirements:
|
46
|
+
version_requirements: *903369160
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-given
|
49
|
+
requirement: &903368910 !ruby/object:Gem::Requirement
|
72
50
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
- 10
|
80
|
-
- 0
|
81
|
-
version: 0.10.0
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
82
55
|
type: :development
|
83
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *903368910
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard-rspec
|
60
|
+
requirement: &903368650 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *903368650
|
69
|
+
- !ruby/object:Gem::Dependency
|
84
70
|
name: cucumber
|
85
|
-
|
71
|
+
requirement: &903368400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
86
78
|
prerelease: false
|
87
|
-
version_requirements:
|
79
|
+
version_requirements: *903368400
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-cucumber
|
82
|
+
requirement: &903368120 !ruby/object:Gem::Requirement
|
88
83
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *903368120
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: simplecov
|
93
|
+
requirement: &903367880 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *903367880
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: growl_notify
|
104
|
+
requirement: &903367600 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *903367600
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: rb-fsevent
|
115
|
+
requirement: &903367360 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
98
121
|
type: :development
|
99
|
-
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *903367360
|
124
|
+
- !ruby/object:Gem::Dependency
|
100
125
|
name: rspec
|
101
|
-
|
126
|
+
requirement: &903367110 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.3.1
|
132
|
+
type: :development
|
102
133
|
prerelease: false
|
103
|
-
version_requirements:
|
134
|
+
version_requirements: *903367110
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: cucumber
|
137
|
+
requirement: &903366870 !ruby/object:Gem::Requirement
|
104
138
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
hash: 55
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
- 10
|
112
|
-
- 0
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
113
142
|
version: 0.10.0
|
114
143
|
type: :development
|
115
|
-
|
116
|
-
|
117
|
-
description:
|
144
|
+
prerelease: false
|
145
|
+
version_requirements: *903366870
|
146
|
+
description: ! 'gimme attempts to bring to Ruby a test double workflow akin to Mockito
|
147
|
+
in Java. Major distinctions include preserving arrange-act-assert in tests, fast
|
148
|
+
feedback for methods the double''s real counterpart may not know how to respond
|
149
|
+
to, no string/symbolic representations of methods, argument captors, and strong
|
150
|
+
opinions (weakly held). '
|
118
151
|
email: searls@gmail.com
|
119
152
|
executables: []
|
120
|
-
|
121
153
|
extensions: []
|
122
|
-
|
123
|
-
extra_rdoc_files:
|
154
|
+
extra_rdoc_files:
|
124
155
|
- LICENSE.txt
|
125
156
|
- README.markdown
|
126
157
|
- README.rdoc
|
127
|
-
files:
|
128
|
-
- .bundle/config
|
158
|
+
files:
|
129
159
|
- .document
|
160
|
+
- .travis.yml
|
130
161
|
- Gemfile
|
131
162
|
- Gemfile.lock
|
163
|
+
- Guardfile
|
132
164
|
- LICENSE.txt
|
133
165
|
- README.markdown
|
134
166
|
- README.rdoc
|
@@ -154,41 +186,49 @@ files:
|
|
154
186
|
- lib/gimme/gives.rb
|
155
187
|
- lib/gimme/matchers.rb
|
156
188
|
- lib/gimme/method_resolver.rb
|
189
|
+
- lib/gimme/rspec_adapter.rb
|
157
190
|
- lib/gimme/test_double.rb
|
158
191
|
- lib/gimme/verifies.rb
|
159
|
-
|
192
|
+
- spec/gimme/captor_spec.rb
|
193
|
+
- spec/gimme/errors_spec.rb
|
194
|
+
- spec/gimme/gives_spec.rb
|
195
|
+
- spec/gimme/matchers_spec.rb
|
196
|
+
- spec/gimme/test_double_spec.rb
|
197
|
+
- spec/gimme/verifies_spec.rb
|
198
|
+
- spec/spec_helper.rb
|
160
199
|
homepage: http://github.com/searls/gimme
|
161
|
-
licenses:
|
200
|
+
licenses:
|
162
201
|
- MIT
|
163
202
|
post_install_message:
|
164
203
|
rdoc_options: []
|
165
|
-
|
166
|
-
require_paths:
|
204
|
+
require_paths:
|
167
205
|
- lib
|
168
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
206
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
207
|
none: false
|
170
|
-
requirements:
|
171
|
-
- -
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
|
174
|
-
segments:
|
208
|
+
requirements:
|
209
|
+
- - ! '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
segments:
|
175
213
|
- 0
|
176
|
-
|
177
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
hash: -312263039
|
215
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
216
|
none: false
|
179
|
-
requirements:
|
180
|
-
- -
|
181
|
-
- !ruby/object:Gem::Version
|
182
|
-
|
183
|
-
segments:
|
184
|
-
- 0
|
185
|
-
version: "0"
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
186
221
|
requirements: []
|
187
|
-
|
188
222
|
rubyforge_project:
|
189
|
-
rubygems_version: 1.
|
223
|
+
rubygems_version: 1.8.6
|
190
224
|
signing_key:
|
191
225
|
specification_version: 3
|
192
|
-
summary:
|
193
|
-
test_files:
|
194
|
-
|
226
|
+
summary: gimme — a low-specification test double library for Ruby
|
227
|
+
test_files:
|
228
|
+
- spec/gimme/captor_spec.rb
|
229
|
+
- spec/gimme/errors_spec.rb
|
230
|
+
- spec/gimme/gives_spec.rb
|
231
|
+
- spec/gimme/matchers_spec.rb
|
232
|
+
- spec/gimme/test_double_spec.rb
|
233
|
+
- spec/gimme/verifies_spec.rb
|
234
|
+
- spec/spec_helper.rb
|
data/.bundle/config
DELETED