Capybara::AsyncRunner
This is a ruby gem for running asynchronous JavaScript code synchronously with Capybara.
Installation
Add this line to your application's Gemfile:
gem 'capybara-async_runner'
And then execute:
$ bundle
Or install it yourself as:
$ gem install capybara-async_runner
Usage
Read this blog post first.
Then check out examples
dir.
How to use
- Setup a directory with command templates
Capybara::AsyncRunner.setup do |config|
config.commands_directory = Rails.root.join('directory/with/templates')
end
- Create a command
class MyCommand < Capybara::AsyncRunner::Command
# specify the name
self.command_name = :my_command
# specify a path to template
self.template = 'template_name'
# specify a response
response :done
end
- Create a template file
// directory/with/templates/template_name.js.erb
yourCode(function(data) {
<%= done(js[:data]) %>
})
- Call the command
Capybara::AsyncRunner.run(:my_command)
# => data from your script
Contributing
- Fork it ( https://github.com/[my-github-username]/capybara-async_runner/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request