motion-stump 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/Gemfile +1 -1
- data/Rakefile +19 -20
- data/{lib/stump → app}/app_delegate.rb +0 -0
- data/lib/motion-stump.rb +6 -14
- data/lib/{stump → motion}/stump_spec_helper.rb +8 -6
- data/lib/stump/metaid.rb +5 -1
- data/lib/stump/metareset.rb +30 -0
- data/lib/stump/mock.rb +10 -10
- data/lib/stump/stub.rb +1 -7
- data/lib/stump/version.rb +1 -1
- data/spec/main_spec.rb +64 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dafe29c6f7a0e5c2425dbed30c336b6ab3a354db
|
4
|
+
data.tar.gz: 6174a4006293ab88a138d6f8d470fdeab9d2a3a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba97813ed8f07dc31bf1dd2a5a078bebc60f019ebb2a41c895bd1b7f8173a16dc54901ea6687d3802a7518722eef643d786b8811ba26bd6522a04030cbdb6bc1
|
7
|
+
data.tar.gz: efd82644bee3d4749b377db7bcbfe32cddec8e998b426966b49f07144ddcf82e06de79719140f1c275e6db36576d059629eb0a37bbf8b145c6943163692a04be
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require "bundler/gem_tasks"
|
3
|
-
|
4
|
-
$:.unshift("/Library/RubyMotion/lib")
|
5
|
-
|
6
|
-
require '
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
sh "
|
18
|
-
sh "
|
19
|
-
|
20
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
$:.unshift("/Library/RubyMotion/lib")
|
5
|
+
require 'motion/project/template/ios'
|
6
|
+
require 'bundler'
|
7
|
+
Bundler.setup :default, :development
|
8
|
+
require 'motion-stump'
|
9
|
+
|
10
|
+
Motion::Project::App.setup do |app|
|
11
|
+
app.name = 'motion-stump'
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Build the gem"
|
15
|
+
task :gem do
|
16
|
+
sh "bundle exec gem build motion-stump.gemspec"
|
17
|
+
sh "mkdir -p pkg"
|
18
|
+
sh "mv *.gem pkg/"
|
19
|
+
end
|
File without changes
|
data/lib/motion-stump.rb
CHANGED
@@ -5,26 +5,18 @@ end
|
|
5
5
|
## Extend Motion config to include our spec helper
|
6
6
|
module Motion; module Project;
|
7
7
|
class Config
|
8
|
-
alias_method :
|
9
|
-
def
|
10
|
-
|
11
|
-
(core + [File.join(File.dirname(__FILE__), 'stump/stump_spec_helper.rb')] + spec_files_before_stump).uniq
|
8
|
+
alias_method :spec_core_files_without_stump, :spec_core_files
|
9
|
+
def spec_core_files
|
10
|
+
spec_core_files_without_stump + [File.join(File.dirname(__FILE__), 'motion/stump_spec_helper.rb')]
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end; end
|
15
14
|
|
16
|
-
|
17
15
|
## Include stump in dev mode
|
18
16
|
Motion::Project::App.setup do |app|
|
19
17
|
app.development do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
File.join(File.dirname(__FILE__), 'stump/stub.rb'),
|
24
|
-
File.join(File.dirname(__FILE__), 'stump/mocks.rb'),
|
25
|
-
File.join(File.dirname(__FILE__), 'stump/mock.rb'),
|
26
|
-
File.join(File.dirname(__FILE__), 'stump/proxy.rb'),
|
27
|
-
File.join(File.dirname(__FILE__), 'stump/app_delegate.rb')
|
28
|
-
].reverse.each {|f| app.files.unshift(f) }
|
18
|
+
stump_lib_dir = File.join(File.dirname(__FILE__), 'stump')
|
19
|
+
stump_files = Dir.glob(stump_lib_dir + "/**/*.rb")
|
20
|
+
app.files.unshift(stump_files)
|
29
21
|
end
|
30
22
|
end
|
@@ -9,17 +9,19 @@ module Stump
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def verify_mocks
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
begin
|
13
|
+
if !Stump::Mocks.failures.nil? && !Stump::Mocks.failures.empty?
|
14
|
+
fails = Stump::Mocks.failures.map {|object, method| "#{object.inspect} expected #{method}"}.join(", ")
|
15
|
+
should.flunk "Unmet expectations: #{fails}"
|
16
|
+
end
|
17
|
+
ensure
|
18
|
+
Stump::Mocks.clear!
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def it_with_mock_verification(description, &block)
|
19
23
|
@after << proc { verify_mocks }
|
20
24
|
it_without_mock_verification(description, &block)
|
21
|
-
ensure
|
22
|
-
Stump::Mocks.clear!
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -29,4 +31,4 @@ begin
|
|
29
31
|
Bacon::Context.class_eval { include Stump::Baconize::ContextExtensions }
|
30
32
|
rescue LoadError
|
31
33
|
puts 'Bacon is not available.'
|
32
|
-
end
|
34
|
+
end
|
data/lib/stump/metaid.rb
CHANGED
@@ -7,7 +7,11 @@ class Object
|
|
7
7
|
|
8
8
|
# Adds methods to a metaclass
|
9
9
|
def meta_def name, &blk
|
10
|
-
meta_eval {
|
10
|
+
meta_eval {
|
11
|
+
define_method(name) {|*args, &block|
|
12
|
+
blk.call(*args, &block)
|
13
|
+
}
|
14
|
+
}
|
11
15
|
end
|
12
16
|
|
13
17
|
# Defines an instance method within a class
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Object
|
2
|
+
def safe_meta_def method_name, &method_body
|
3
|
+
metaclass.remember_original_method(method_name)
|
4
|
+
meta_eval {
|
5
|
+
define_method(method_name) {|*args, &block|
|
6
|
+
method_body.call(*args, &block)
|
7
|
+
}
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def reset(method_name)
|
12
|
+
metaclass.restore_original_method(method_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def remember_original_method(method_name)
|
18
|
+
alias_method "__original_#{method_name}".to_sym, method_name if method_defined?(method_name)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def restore_original_method(method_name)
|
23
|
+
original_method_name = "__original_#{method_name}".to_sym
|
24
|
+
if method_defined?(original_method_name)
|
25
|
+
alias_method method_name, original_method_name
|
26
|
+
remove_method original_method_name
|
27
|
+
end
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
data/lib/stump/mock.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
class Object
|
2
2
|
# Create a mock method on an object. A mock object will place an expectation
|
3
3
|
# on behavior and cause a test failure if it's not fulfilled.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# ==== Examples
|
6
6
|
#
|
7
7
|
# my_string = "a wooden rabbit"
|
8
8
|
# my_string.mock!(:retreat!, :return => "run away! run away!")
|
9
9
|
# my_string.mock!(:question, :return => "what is the airspeed velocity of an unladen sparrow?")
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# # test/your_test.rb
|
12
12
|
# my_string.retreat! # => "run away! run away!"
|
13
13
|
# # If we let the test case end at this point, it fails with:
|
14
14
|
# # Unmet expectation: #<Sparrow:1ee7> expected question
|
15
15
|
#
|
16
|
-
def mock!(method, options = {}, &block)
|
16
|
+
def mock!(method, options = {}, &block)
|
17
17
|
Stump::Mocks.add([self, method])
|
18
|
-
|
18
|
+
|
19
19
|
behavior = if block_given?
|
20
|
-
lambda do |*args|
|
20
|
+
lambda do |*args|
|
21
21
|
raise ArgumentError if block.arity >= 0 && args.length != block.arity
|
22
|
-
|
22
|
+
|
23
23
|
Stump::Mocks.verify([self, method])
|
24
24
|
block.call(*args)
|
25
25
|
end
|
@@ -29,20 +29,20 @@ class Object
|
|
29
29
|
yield(options[:yield])
|
30
30
|
end
|
31
31
|
else
|
32
|
-
lambda do |*args|
|
32
|
+
lambda do |*args|
|
33
33
|
Stump::Mocks.verify([self, method])
|
34
34
|
return options[:return]
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
safe_meta_def method, &behavior
|
39
39
|
end
|
40
40
|
|
41
41
|
def should_not_call(method)
|
42
42
|
behavior = lambda do |*args|
|
43
43
|
should.flunk "Umet expectations: #{method} expected to not be called"
|
44
44
|
end
|
45
|
-
|
45
|
+
safe_meta_def method, &behavior
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,7 @@ module Kernel
|
|
50
50
|
# Create a pure mock object rather than mocking specific methods on an object.
|
51
51
|
#
|
52
52
|
# ==== Examples
|
53
|
-
#
|
53
|
+
#
|
54
54
|
# my_mock = mock(:thing, :return => "whee!")
|
55
55
|
# my_mock.thing # => "whee"
|
56
56
|
#
|
data/lib/stump/stub.rb
CHANGED
@@ -13,13 +13,7 @@ class Object
|
|
13
13
|
def stub!(method_name, options = {}, &stubbed)
|
14
14
|
behavior = (block_given? ? stubbed : lambda { return options[:return] })
|
15
15
|
|
16
|
-
|
17
|
-
self
|
18
|
-
end.instance_eval {
|
19
|
-
define_method(method_name) { |*args, &block|
|
20
|
-
behavior.call(*args, &block)
|
21
|
-
}
|
22
|
-
}
|
16
|
+
safe_meta_def method_name, &behavior
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
data/lib/stump/version.rb
CHANGED
data/spec/main_spec.rb
CHANGED
@@ -6,6 +6,10 @@ describe "Application 'stump-test'" do
|
|
6
6
|
return Dog.new
|
7
7
|
end
|
8
8
|
|
9
|
+
def self.kind
|
10
|
+
'Mammal'
|
11
|
+
end
|
12
|
+
|
9
13
|
def bark
|
10
14
|
"Woof!"
|
11
15
|
end
|
@@ -31,7 +35,7 @@ describe "Application 'stump-test'" do
|
|
31
35
|
end
|
32
36
|
|
33
37
|
describe "#stub!" do
|
34
|
-
it "should stub a class method" do
|
38
|
+
it "should stub a class method" do
|
35
39
|
Dog.stub!(:thing, return: :thing)
|
36
40
|
Dog.should.not.be.nil
|
37
41
|
Dog.thing.should == :thing
|
@@ -53,7 +57,7 @@ describe "Application 'stump-test'" do
|
|
53
57
|
my_obj.hello("foo", "bar").should.be == "foo,bar"
|
54
58
|
end
|
55
59
|
end
|
56
|
-
|
60
|
+
|
57
61
|
describe "#stub" do
|
58
62
|
it "should create a pure stub" do
|
59
63
|
my_stub = stub(:thing, return: "dude, a thing!")
|
@@ -108,7 +112,7 @@ describe "Application 'stump-test'" do
|
|
108
112
|
end
|
109
113
|
|
110
114
|
describe "#mock" do
|
111
|
-
it "should create pure mock" do
|
115
|
+
it "should create pure mock" do
|
112
116
|
my_mock = mock(:hello, return: "hi")
|
113
117
|
my_mock.hello.should == "hi"
|
114
118
|
end
|
@@ -141,4 +145,61 @@ describe "Application 'stump-test'" do
|
|
141
145
|
end
|
142
146
|
end
|
143
147
|
end
|
148
|
+
|
149
|
+
describe "#reset" do
|
150
|
+
describe "stubbing" do
|
151
|
+
it "should restore original class method" do
|
152
|
+
Dog.stub!(:kind, return: 'Reptile')
|
153
|
+
Dog.kind.should == 'Reptile'
|
154
|
+
Dog.reset(:kind)
|
155
|
+
Dog.kind.should == 'Mammal'
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should restore original instance method" do
|
159
|
+
@dog.stub!(:bark, return: 'Meow!')
|
160
|
+
@dog.bark.should == 'Meow!'
|
161
|
+
@dog.reset(:bark)
|
162
|
+
@dog.bark.should == 'Woof!'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe "mocking" do
|
167
|
+
it "should restore original class method" do
|
168
|
+
Dog.mock!(:kind, return: 'Reptile')
|
169
|
+
Dog.kind.should == 'Reptile'
|
170
|
+
Dog.reset(:kind)
|
171
|
+
Dog.kind.should == 'Mammal'
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should restore original instance method" do
|
175
|
+
@dog.mock!(:bark, return: 'Meow!')
|
176
|
+
@dog.bark.should == 'Meow!'
|
177
|
+
@dog.reset(:bark)
|
178
|
+
@dog.bark.should == 'Woof!'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "after each scenario" do
|
184
|
+
it "should verify mocks" do
|
185
|
+
Should.class_eval do
|
186
|
+
def ignored_flunk(message)
|
187
|
+
end
|
188
|
+
|
189
|
+
alias_method :original_flunk, :flunk
|
190
|
+
alias_method :flunk, :ignored_flunk
|
191
|
+
end
|
192
|
+
|
193
|
+
Dog.mock!(:kind, return: 'Reptile')
|
194
|
+
1.should == 1
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should have cleared mocks from the previous scenario" do
|
198
|
+
1.should == 1
|
199
|
+
|
200
|
+
Should.class_eval do
|
201
|
+
alias_method :flunk, :original_flunk
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
144
205
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-stump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: motion-redgreen
|
@@ -51,14 +51,15 @@ files:
|
|
51
51
|
- License.txt
|
52
52
|
- README.md
|
53
53
|
- Rakefile
|
54
|
+
- app/app_delegate.rb
|
54
55
|
- lib/motion-stump.rb
|
55
|
-
- lib/
|
56
|
+
- lib/motion/stump_spec_helper.rb
|
56
57
|
- lib/stump/metaid.rb
|
58
|
+
- lib/stump/metareset.rb
|
57
59
|
- lib/stump/mock.rb
|
58
60
|
- lib/stump/mocks.rb
|
59
61
|
- lib/stump/proxy.rb
|
60
62
|
- lib/stump/stub.rb
|
61
|
-
- lib/stump/stump_spec_helper.rb
|
62
63
|
- lib/stump/version.rb
|
63
64
|
- motion-stump.gemspec
|
64
65
|
- spec/main_spec.rb
|