WebfaceRails
RubyOnRails integration with Webface.js
Installation
add gem 'webface_rails' to Gemfile and run bundle install
Running generators
To run the generator:
rails generate webface or rails g webface
By default it uses Rails.root path to install the gem. You can pass root_path argument to redefine root path in your project. It might be helpful when installing the gem into Rails Engine, e.g.:
rails g webface --root_path absolute_path_to_your_project
The generator will give you necessary files and dir structure inside the spec/ dir to
run webface tests. To be more specific, it will do the following
- Install webface as a submodule under
app/assets/javascripts/webface.js. If you already have it installed, it will use the path specified in .gitmodules - Create webface unit test dir under
spec/webface - Copy there a bunch of files necessary to run unit tests
- Add
node_modulesdirs to .gitignore - Symlink your
app/assets/javascriptsintospec/webface/sourceandapp/assets/javascriptsintospec/webface/webface_source. This is necessary to properly import the files you're testing. - Install node_modules in
app/assets/javascripts. If it doesn't have apackage.jsonfile, it will copy the one used by webface. - Symlink
app/assets/javascripts/node_modulestospec/webface/node_modules - And finally, symlink the
app/assets/javascripts/webface.js(or whatever the path is) intospec/webface/webface_source
Running unit tests
After you run the generators, you should be able to run unit tests with
a) spec/webface/run_test or
b) by launching the test server with node spec/webface/test_server.js and navigating your browser to localhost:8080. You should see a sample test there.
Look at the spec/webface/components/my_component.test.js file for examples on how to write unit tests.
Unit tests are written with mocha & chai.