Comments (5)
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.
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.
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.
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.
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)
- Is there a way to change the font color for title text? HOT 1
- Not able to run a project with formotion HOT 1
- color of a text field HOT 2
- Updating runtime dependency for motion-require HOT 1
- How to call reload_data on a form? HOT 2
- 'willDisplayCell' delegate method not called HOT 1
- Observe to update after a change in a form field HOT 2
- Formotion panel sometimes does not display until tap or scroll registered HOT 2
- form.render returning an empty hash HOT 3
- Styling Submit button HOT 1
- Change caret / tint color HOT 2
- Options row causes crash in specific cases
- Picker broken for ios8? HOT 1
- subform row crashes HOT 1
- How to dynamically assign rows to Formotion table
- Specific dates cannot be selected HOT 2
- How to get UIView object for a row HOT 1
- Subforms with multiple views per page HOT 2
- Picker items updating text on_change but not value in form HOT 3
- Cyclical dependencies and `motion_require`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formotion.