Using RSpec for iPhone Controllers

Finally, I get RSpec support after spending several hours on the weekend. Now I'm stuck trying to figure out how to claim that the parameters are really passed to the controller. I follow the bowling from the Ruby / Cocoa example and adapting it for the iPhone SDK. I made a more detailed record of my progress on my blog.so I’ll postpone the whole story there. In short, I followed the tutorial right down to where you need to pass the character value from the text box to the Bowling object. RSpec continues to complain that "Spec :: Mocks :: MockExpectationError in" OSX :: BowlingController should send the pin value to the Mock bowling object. Bowling expected: roll with (10), but received it (without arguments). / test / bowling _controller_spec.rb: 38: "Even if I'm sure I pass the value. Here is my code. Can someone tell me where I am going wrong?

bowling_controller_spec.rb

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

BowlingController.h

#import <Foundation/Foundation.h>

@class UITextField;
@class Bowling;

@interface BowlingController : NSObject {
    UITextField* pins;
    Bowling* bowling;
}
@property (nonatomic, retain) UITextField* pins;
@property (nonatomic, retain) Bowling* bowling;

-(void) roll;
@end

BowlingController.m

#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() { }

Bowling.h

#import <Foundation/Foundation.h>

@interface Bowling : NSObject {

}
- (void) roll:(int) pins;
@end

Bowling.m

#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() { }
+3
source share
2 answers

RubyCocoa iPhone. , , - .

, , OS X, , iPhone.

RubyCocoa iPhone, , , , , .

+3

Howdy! , Ruby/ Cocoa Objective C - , , , , Ruby . - Cocoa, Cocoa . ruby.

roll() , , , .

, , , . !

0

Source: https://habr.com/ru/post/1699364/


All Articles