Permalink
Browse files

add motion spec helper

  • Loading branch information...
1 parent e527a97 commit 44562cfb6727b94421b2268f77dbd66b45c3f417 @siuying committed Jul 11, 2012
Showing with 96 additions and 108 deletions.
  1. +1 −0 .gitignore
  2. +0 −20 Gemfile.lock
  3. +5 −0 app/app_delegate.rb
  4. +0 −73 config/hoe.rb
  5. +0 −15 config/requirements.rb
  6. +13 −0 lib/motion-stump.rb
  7. +33 −0 lib/stump/stump_spec_helper.rb
  8. +44 −0 spec/main_spec.rb
View
@@ -0,0 +1 @@
+Gemfile.lock
View
@@ -1,20 +0,0 @@
-PATH
- remote: .
- specs:
- motion-stump (0.1.0)
- motion-define-method (~> 0.1.2)
-
-GEM
- remote: http://rubygems.org/
- specs:
- motion-define-method (0.1.2)
- motion-redgreen (0.0.2)
- rake (0.9.2.2)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- motion-redgreen
- motion-stump!
- rake
View
@@ -0,0 +1,5 @@
+class AppDelegate
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
+ true
+ end
+end
View
@@ -1,73 +0,0 @@
-require 'stump/version'
-
-AUTHOR = 'Jeremy McAnally' # can also be an array of Authors
-EMAIL = "jeremy@entp.com"
-DESCRIPTION = "Stubbing and mocking that isn't painful."
-GEM_NAME = 'stump' # what ppl will type to install your gem
-RUBYFORGE_PROJECT = 'stump' # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
-EXTRA_DEPENDENCIES = [
-# ['activesupport', '>= 1.3.1']
-] # An array of rubygem dependencies [name, version]
-
-@config_file = "~/.rubyforge/user-config.yml"
-@config = nil
-RUBYFORGE_USERNAME = "unknown"
-def rubyforge_username
- unless @config
- begin
- @config = YAML.load(File.read(File.expand_path(@config_file)))
- rescue
- puts <<-EOS
-ERROR: No rubyforge config file found: #{@config_file}
-Run 'rubyforge setup' to prepare your env for access to Rubyforge
- - See http://newgem.rubyforge.org/rubyforge.html for more details
- EOS
- exit
- end
- end
- RUBYFORGE_USERNAME.replace @config["username"]
-end
-
-
-REV = nil
-# UNCOMMENT IF REQUIRED:
-# REV = YAML.load(`svn info`)['Revision']
-VERS = Stump::VERSION::STRING + (REV ? ".#{REV}" : "")
-RDOC_OPTS = ['--quiet', '--title', 'stump documentation',
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-class Hoe
- def extra_deps
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
- @extra_deps
- end
-end
-
-# Generate all the Rake tasks
-# Run 'rake -T' to see list of generated tasks (from gem root directory)
-$hoe = Hoe.new(GEM_NAME, VERS) do |p|
- p.developer(AUTHOR, EMAIL)
- p.description = DESCRIPTION
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/test_*.rb"]
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
-
- # == Optional
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
- #p.extra_deps = EXTRA_DEPENDENCIES
-
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
- end
-
-CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
-PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
-$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
-$hoe.rsync_args = '-av --delete --ignore-errors'
-$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -1,15 +0,0 @@
-require 'fileutils'
-include FileUtils
-
-require 'rubygems'
-%w[rake hoe newgem rubigen].each do |req_gem|
- begin
- require req_gem
- rescue LoadError
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
- puts "Installation: gem install #{req_gem} -y"
- exit
- end
-end
-
-$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
View
@@ -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
[
@@ -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
View
@@ -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.