Skip to content

Commit

Permalink
add motion spec helper
Browse files Browse the repository at this point in the history
  • Loading branch information
siuying committed Jul 11, 2012
1 parent e527a97 commit 44562cf
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gemfile.lock
20 changes: 0 additions & 20 deletions Gemfile.lock

This file was deleted.

5 changes: 5 additions & 0 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
true
end
end
73 changes: 0 additions & 73 deletions config/hoe.rb

This file was deleted.

15 changes: 0 additions & 15 deletions config/requirements.rb

This file was deleted.

13 changes: 13 additions & 0 deletions lib/motion-stump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
raise "This file must be required within a RubyMotion project Rakefile."
end

## Extend Motion config to include our spec helper
module Motion; module Project;
class Config
alias_method :spec_files_before_stump, :spec_files
def spec_files
core = Dir.chdir(motiondir + '/lib/motion') { (['spec.rb'] + Dir.glob(File.join('spec', 'helpers', '*.rb'))).map { |x| File.expand_path(x) } }
(core + [File.join(File.dirname(__FILE__), 'lib/stump_spec_helper.rb')] + spec_files_before_stump).uniq
end
end
end; end

## Include supports for define_method
require 'motion-define-method'

## Include stump in dev mode
Motion::Project::App.setup do |app|
app.development do
[
Expand Down
33 changes: 33 additions & 0 deletions lib/stump/stump_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Stump
module Baconize
module ContextExtensions
def self.included(base)
base.class_eval do
alias_method :it_without_mock_verification, :it
alias_method :it, :it_with_mock_verification
end
end

def verify_mocks
puts "verify_mocks"
if !Stump::Mocks.failures.nil? && !Stump::Mocks.failures.empty?
fails = Stump::Mocks.failures.map {|object, method| "#{object.inspect} expected #{method}"}.join(", ")
should.flunk "Unmet expectations: #{fails}"
end
end

def it_with_mock_verification(description, &block)
@after << proc { verify_mocks }
it_without_mock_verification(description, &block)
ensure
Stump::Mocks.clear!
end
end
end
end

begin
Bacon::Context.class_eval { include Stump::Baconize::ContextExtensions }
rescue LoadError
puts 'Bacon is not available.'
end
44 changes: 44 additions & 0 deletions spec/main_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe "Application 'stump-test'" do
class Hello
end

it "stub on object" do
Hello.stub!(:thing, :return => "hey!")
Hello.should.not.be.nil
Hello.thing.should == "hey!"

my_obj = Object.new
my_obj.stub!(:hello)
my_obj.hello.should.be.nil
end

it "should create pure stub" do
my_stub = stub(:thing, :return => "dude, a thing!")
my_stub.thing.should == "dude, a thing!"
end

it "should mock object" do
my_object = "things are fun"
my_object.mock!(:fancy, :return => "ooo fancy!")
my_object.mock!(:tancy, :return => "ooo tancy!")
my_object.fancy.should == 'ooo fancy!'
end

# it "should create pure mock" do
# my_mock = mock(:hello, :return => "what fun is this?")
# my_mock.hello.should == "what fun is this?"
# end

# class Greeting
# def bonjour
# "Bonjour!"
# end
# end

# it "should use proxy objects" do
# greet_me = Greeting.new
# greet_me.proxy!(:bonjour)
# greet_me.bonjour # => "Bonjour!"
# end

end

0 comments on commit 44562cf

Please sign in to comment.