Skip to content

ejholmes/mockjax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'

About

Define ajax stubs in your request specs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published