Define ajax stubs in your request specs.
JavaScript Ruby
Switch branches/tags
Nothing to show
Latest commit 467698a Jul 1, 2012 @ejholmes Cleanup
Failed to load latest commit information.
app/assets/javascripts Port support files to gem. Jun 24, 2012
lib Cleanup Jul 1, 2012
spec `stub_ajax` feels more explicit. Jun 24, 2012
.gitignore Initial commit. Jun 24, 2012
Gemfile Initial commit. Jun 24, 2012
LICENSE Initial commit. Jun 24, 2012 Update master Jun 25, 2012
Rakefile Just default to pulling from github. Jun 24, 2012
mockjax.gemspec Add json gem as dependency. Jun 24, 2012

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'


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'