Mockjax travis-ci

Mockjax gem for rails and rack applications. Define javascript mocks in your request specs


Add this line to your application's Gemfile:

gem 'mockjax'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mockjax


Assuming you're using capybara...


# spec/spec_helper.rb = {
    use Rack::Mockjax
    run MyApp

Rails 3

# config/initializers/test.rb
config.middleware.use Rack::Mockjax

Then define your stubs like you would with any other stubbing library:

before do
  stub_ajax url: '/test', responseText: { message: 'hello world' }

Now we can make requests to /test from javascript and our mock will be used. Awesome!

$.getJSON '/test', (data) -> console.log(data.message)
# => 'hello world'


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request