README.md in netzke-testing-0.12.1 vs README.md in netzke-testing-0.12.2

- old
+ new

@@ -1,6 +1,6 @@ -# Netzke Testing +# Netzke Testing [![Gem Version](https://fury-badge.herokuapp.com/rb/netzke-testing.png)](http://badge.fury.io/rb/netzke-testing) This gem helps with development and testing of Netzke components. In parcticular, it helps you with: * isolated component development * client-side testing of components with Mocha and Expect.js @@ -73,10 +73,24 @@ See the [source code](https://github.com/netzke/netzke-testing/tree/master/app/assets/javascripts/netzke/testing/helpers) for currently implemented helpers (TODO: document them). Also, refer to other Netzke gems source code (like netzke-core and netzke-basepack) to see examples using the helpers. +## Adding custom spec helpers + +You may add (or require, by means of Sprockets) additional helpers in `app/assets/javascripts/netzke/testing.js`, which will be included in the testing template *after* the helpers provided by netzke-testing. For example: + + // in app/assets/javascripts/netzke/testing.js + //= require_tree ./testing + + # in app/assets/javascripts/netzke/testing/grid.js.coffee + Ext.apply window, + enableColumnFilter: (column, value) -> + # ... + +After this the `enableColumnFilter` helper will be available in your Mocha specs. + ## Testing with selenium webdriver Generate the `netzke_mocha_spec.rb` file that will automatically run the specs that follow a certain naming convention: rails g netzke_testing @@ -103,12 +117,46 @@ end end The `run_mocha_spec` here will run a Mocha spec from `spec/grid_with_destructive_button.js.coffee`. -You can explicitely specify a component to run the spec on (in order to override the convention): +You can explicitely specify a component to run the spec on: run_mocha_spec 'grid_with_destructive_button', component: 'UserGrid' + +To investigate the problem in case of a failing Mocha spec, set `stop_on_error` to `true` (this will keep the browser open on the failed spec): + + run_mocha_spec 'grid_with_destructive_button', stop_on_error: true + +(in this case you'll have to terminate the specs by pressing `ctrl+c`) + +## Setting timeout for longer running JS specs + +Netzke-testing by default assumes that your specs do not take longer than 5 seconds, and mark them failed if they do. If your spec are as complex as taking longer than that, you can increase this value in an initializer, e.g.: + + # in config/initializers/netzke.rb + Netzke::Testing.setup do |config| + config.js_timeout = 10 # seconds + end + +You could also set this in `spec_helper.rb` like this: + + Netzke::Testing.js_timeout = 10 + +However, keep in mind, that this won't have effect on running specs manually in the browser (by specifying the `spec` URL parameter, as shown above). For this case, you may provide the `timeout` URL paramter (takes precedence over `Netzke::Testing.js_timeout`): + + http://localhost:3000/netzke/components/UserGrid?spec=user_grid&timeout=10 + +## Asynchronous helpers + +Asynchronous helpers like `wait` can either call the provided callback function, or (if none was provided) return a promise, so you can do: + + wait(). + .then -> + doSomething() + wait() + .then + doSomeMore() ## Requirements * Ruby >= 2.0.0 * Rails ~> 4.2.0