Skip to content

thachck/jquery_mockjax_rails

Repository files navigation

jquery_mockjax_rails

Build Status

This gem provides:

Requirements

  • Rails 3.1 or later
  • Assets pipeline enabled
  • jQuery
  • Rspec/Capybara integration tests

Installation

Add the jquery_mockjax_rails gem to your Gemfile

group :test do
  gem 'jquery_mockjax_rails'
end

And run bundle install

Getting Started

Stub the ajax request in a before block

describe 'My integration spec', js: true do

  before do
    stub_ajax url: '/api/path', responseText: { message: 'message' }
  end
end

Once the browser has been lauched, open the JS console and test the mocked response

$.getJSON('/api/path', function(data) { console.log(data.message) }); # => message

Acknowledgements

The original idea has come from ejholmes, however, the gem has been deprecated and does not work with current Rails 3 application using rspec/capybara integration test, so I've decided to re-write the gem from scratch. Most of the core code pieces have been emerged from ejholmes's work.

Contributing

Pull requests are more than welcome. Before submitting pull requests, please make sure your changes are covered with tests.

About

Rspec integration test powered with jQuery Mockjax

Resources

License

Stars

Watchers

Forks

Packages

No packages published