Coder Social home page Coder Social logo

Comments (5)

clayallsopp avatar clayallsopp commented on September 13, 2024

The reason your text_field is null is because the viewDidLoad#super was not called, and it absolutely needs to be called (it's where Formotion does all of its setup). What errors were you getting without the RUBYMOTION_ENV == 'test' call?

And as for the triggering navigation button thing, you need to use the standard RubyMotion UI testing libraries. I'm not totally sure how well those work for navigation buttons, but you can try something like tap 'Save'?

from formotion.

bsbodden avatar bsbodden commented on September 13, 2024

brian.face << :egg

I uncommented the test environment check and I no longer get an error if I don't reference the controller in scope. So just with:

describe "TodoController" do

The #viewDidLoad method works just fine in testing. If I add a test context controller as in:

describe "TodoController" do
  tests TodoController

I get:

NoMethodError: undefined method `sections' for nil:NilClass
    form_controller.rb:40:in `viewDidLoad': TodoController - saves changes made to a todo
    todo_controller.rb:12:in `viewDidLoad'
    ui.rb:209:in `window'
    ui.rb:182:in `block in extended:'
    spec.rb:272:in `block in run_before_filters'
    spec.rb:272:in `block in run_before_filters'
    spec.rb:403:in `execute_block'
    spec.rb:272:in `run_before_filters'
    spec.rb:292:in `run'

Removing the controller scope removes all the interaction helpers methods like #tap. That why I was trying to get to the @controller.save method directly.

Row Interaction

The textfield out of the row still keeps on coming back as nil.

I can see that the row is the correct one. The puts above returns:

ROW:: key => name, value => Buy Milk, title => name

Calling @controller.save produces the errors below (even if I haven't been able to change any values on the row).

RuntimeError: NSInternalInconsistencyException: attempt to delete row 0 from section 0 which only contains 0 rows before the update
    todos_controller.rb:27:in `todoChanged:': TodoController - saves changes made to a todo
    model.rb:246:in `issue_notification:'
    model.rb:372:in `block in save:'
    model.rb:389:in `call_hooks:'
    model.rb:359:in `save:'
    validatable.rb:37:in `save:'
    todo_controller.rb:19:in `save'
    spec.rb:279:in `block in run_spec_block'
    spec.rb:403:in `execute_block'
    spec.rb:279:in `run_spec_block'
    spec.rb:294:in `run'

I'll keep on playing with it until I way to approach this kind of testing. If you want to take a look I just pushed it to my code to:

https://github.com/integrallis/motion-todos

Cheers & Thanks

from formotion.

clayallsopp avatar clayallsopp commented on September 13, 2024

So one thing you should try is mimicking how Formotion does controller-testing, which is to re-device the controller method:

describe "FormController/SwitchRow" do
  tests Formotion::FormController

  def controller
    row_settings = { ... }
    @form ||= Formotion::Form.new(row_settings)

    @controller ||= Formotion::FormController.alloc.initWithForm(@form)
  end

  it "should change row value when tapped" do
    # etc
  end
end

I'm not convinced that simply re-assigning the @controller instance variable will work, and this was a problem I ran into when writing the functional tests for Formotion.

See https://github.com/clayallsopp/formotion/blob/master/spec/functional/switch_row_spec.rb, and all the other tests in here: https://github.com/clayallsopp/formotion/tree/master/spec/functional

from formotion.

bsbodden avatar bsbodden commented on September 13, 2024

Awesome, I'l give that I try and report back. I'll keep the topic open until I find a good resolution and leave that app as a example to others.

from formotion.

bsbodden avatar bsbodden commented on September 13, 2024

Overriding the controller method worked.

describe "TodoController" do
  tests TodoController

  before do
    @now = NSDate.new
    @todo = Todo.create :name => "Buy Milk",
                        :description => "We need some Milk",
                        :due_date => @now
    @controller = TodoController.create(@todo)
    @form = @controller.instance_variable_get("@form")
    @save_button = @controller.instance_variable_get("@save_button")
  end

  def controller
    @controller
  end

The only remaining problems is that I can seem to be able to tap the save button in the navbar, if I put a button anywhere else it's find but for some reason the one in ruby controller.navigationItem.rightBarButtonItem is not available to the test context.

from formotion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.