phoet
phoet

Reputation: 18845

setting up controller for test

i'm trying to write a functional test for my controller in rubymotion using bacon.

in my controller i have some code that populates some data:

def viewWillAppear(animated)
  song_text.text = chant.song_text
  ...
end

i am setting the chant variable when i push that controller to the navigation-controller.

this works fine in the app, but when i try to do that in a before-block of the spec it does not work, because viewWillAppear gets called before the block and it fails with a NoMethodError: undefined method 'song_text' for nil:NilClass.

is there some way to handle this situation? is there some other way to populate the data or use a different method than viewWillAppear?

Upvotes: 0

Views: 430

Answers (2)

phoet
phoet

Reputation: 18845

The RubyMotion support answered my support ticket indicating, that this is the expected behavior of controllers in bacon.

I worked around the whole thing by stubbing my class under test in the bacon spec like so:

# spec/chant_controller_spec.rb
class ChantControllerStub < ChantController
  def chant
    @chant ||= create_chant
  end
end

describe "ChantController" do
  tests ChantControllerStub

  it "displays a chant" do
    view('verse').should.not == nil
  end
end

Upvotes: 0

BSB
BSB

Reputation: 1705

I've experience a similar issue that was solved by calling the super method in the viewWillAppear method

Upvotes: 3

Related Questions