No commit activity in last 3 years
No release in over 3 years
Ruby gem for using jquery mockjax within rspec examples
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Dependencies

Development

Runtime

>= 0
>= 0
 Project Readme

Mockjax travis-ci

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

Installation

Add this line to your application's Gemfile:

gem 'mockjax'

Usage

Assuming you're using capybara...

Rack

# spec/spec_helper.rb

Capybara.app = Rack::Build.new {
    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' }
end

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'