Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing RSpec for iPhone Controllers
    primarykey
    data
    text
    <p>I'm finally getting the hang of RSpec after spending a couple of hours over the weekend. Now I'm stuck trying to figure out how to assert that parameters are indeed passed into the controller. I'm following the <a href="http://blog.8thlight.com/articles/2008/04/20/bowled-over-by-rubycocoa" rel="nofollow noreferrer">Bowled over by Ruby/Cocoa example</a> and adapting it for the iPhone SDK. I've done a more detailed <a href="http://codeforfun.wordpress.com/2008/11/10/rspec-for-iphone-development/" rel="nofollow noreferrer">writeup of my progress on my blog</a> so I'll defer there for the entire story. In short I've followed the tutorial all the way up to where you need to pass the pin value from the text field into the Bowling object. RSpec keeps complaining that, <em>"Spec::Mocks::MockExpectationError in ‘OSX::BowlingController should send the pin value to the bowling object’ Mock ‘Bowling’ expected :roll with (10) but received it with (no args) ./test/bowling_controller_spec.rb:38:”</em> Even as I'm certain that I'm passing a value in. Here's my code. Can someone tell me where I'm going wrong?</p> <p><strong>bowling_controller_spec.rb</strong></p> <pre><code>require File.dirname(__FILE__) + '/test_helper' require "BowlingController.bundle" OSX::ns_import :BowlingController include OSX describe BowlingController do before(:each) do @controller = BowlingController.new @bowling = mock('Bowling') @text_field = mock('Pins') @text_field.stub!(:intValue).and_return(10) @controller.pins = @text_field end it "should roll a ball" do @controller.roll end it "should roll a ball and get the value from the pins outlet" do @text_field.should_receive(:intValue).and_return(0) @controller.roll end it "should be an OSX::NSObject" do @controller.is_a?(OSX::NSObject).should == true end it "should have an outlet to a bowling object" do @controller.bowling = @bowling end it "should send the pin value to the bowling object" do @controller.bowling = @bowling @bowling.should_receive(:roll).with(10) @controller.roll end end </code></pre> <p><strong>BowlingController.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @class UITextField; @class Bowling; @interface BowlingController : NSObject { UITextField* pins; Bowling* bowling; } @property (nonatomic, retain) UITextField* pins; @property (nonatomic, retain) Bowling* bowling; -(void) roll; @end </code></pre> <p><strong>BowlingController.m</strong></p> <pre><code>#import "BowlingController.h" #import "Bowling.h" @implementation BowlingController @synthesize pins; @synthesize bowling; -(void) roll{ [self.bowling roll:[self.pins intValue]]; } @end // This initialization function gets called when we import the Ruby module. // It doesn't need to do anything because the RubyCocoa bridge will do // all the initialization work. // The rbiphonetest test framework automatically generates bundles for // each objective-c class containing the following line. These // can be used by your tests. void Init_BowlingController() { } </code></pre> <p><strong>Bowling.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface Bowling : NSObject { } - (void) roll:(int) pins; @end </code></pre> <p><strong>Bowling.m</strong></p> <pre><code>#import "Bowling.h" @implementation Bowling - (void) roll:(int) pins{ } @end // This initialization function gets called when we import the Ruby module. // It doesn't need to do anything because the RubyCocoa bridge will do // all the initialization work. // The rbiphonetest test framework automatically generates bundles for // each objective-c class containing the following line. These // can be used by your tests. void Init_Bowling() { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload