MacSpec is a (yet) feature minimal RSpec clone that is specifically built to work with MacRuby. It is built ontop of MiniTest that ships with MacRuby and works out of the box with the MacRuby App Template for Xcode. All you have to do is to replace two lines of code and start writing your tests. No special command for running tests required. Just set your active Target to Test and hit Cmd-B.
MacSpec ships with a testing framework similar to RSpec’s.
The matchy matcher system is built in. (-> github.com/jm/matchy)
Even a mocking framework is built in.
$sudo macgem install MacSpec
For Starters:
Create a brandnew MacRuby Application with the Xcode template that ships with MacRuby. (Btw Have you installed MacRuby-0.5 already? www.macruby.org/downloads.html )
Open the stub_test.rb file that is located inside the Tests group and replace the content with:
require "rubygems" require "MacSpec" describe "MacSpec TestCase" do before do # This gets executed before each test. (Like setup) # Instance variables that are declared # inside this block will be handed down to all # tests. @obj = Object.new end after do # you guess it! end it "should work!" do # this is the body of a test @obj.should_receive(:hello).with("object").and_return("Hello MacSpec") @obj.hello("object").should == "Hello MacSpec" end describe "Nested TestCase" do it "has access to the stuff that has been defined in the outer before blocks" do @obj.stub!(:some_method) lambda {@obj.some_method}.should_not raise_error end end end
Now set the active target to ‘Unit Tests’ and hit Cmd-B.
The highest priority feature will always be MacRuby compatibility. We will expand MacSpec’s feature set towards RSpec’s feature set step by step.
With nested describe blocks, chained setup and teardown, fit and xit, shared_example_groups
With mock objects, method stubs and method expectations (aka partials)
Copyright © 2010 Matthias Hennemeyer. See LICENSE for details. matchy is © 2008 Jeremy McAnally