All Projects → thoughtbot → Capybara_discoball

thoughtbot / Capybara_discoball

Licence: mit
Spin up an external server just for Capybara

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Capybara discoball

dredd-rack
The Dredd API blueprint testing tool for your Rack applications.
Stars: ✭ 50 (-56.9%)
Mutual labels:  rack, testing-tools
Acot
💎 Accessibility Testing Framework. More accessible web, all over the world.
Stars: ✭ 112 (-3.45%)
Mutual labels:  testing-tools
Beanmother
A library for setting up Java objects as test data.
Stars: ✭ 102 (-12.07%)
Mutual labels:  testing-tools
Scala Pact
A Scala implementation of CDC using the Pact standard
Stars: ✭ 106 (-8.62%)
Mutual labels:  testing-tools
Cuba
Rum based microframework for web development.
Stars: ✭ 1,385 (+1093.97%)
Mutual labels:  rack
Mitm Scripts
🔄 A collection of mitmproxy inline scripts
Stars: ✭ 109 (-6.03%)
Mutual labels:  testing-tools
Mongodb Memory Server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
Stars: ✭ 1,376 (+1086.21%)
Mutual labels:  testing-tools
Kubernaut
Instant ephemeral Kubernetes clusters for development and testing
Stars: ✭ 115 (-0.86%)
Mutual labels:  testing-tools
Faker
Go (Golang) Fake Data Generator for Struct
Stars: ✭ 1,698 (+1363.79%)
Mutual labels:  testing-tools
Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (-8.62%)
Mutual labels:  testing-tools
Rack Weixin
微信公众平台 开放消息接口 Rack Middleware
Stars: ✭ 105 (-9.48%)
Mutual labels:  rack
Consolemock
A tool for testing console logs
Stars: ✭ 103 (-11.21%)
Mutual labels:  testing-tools
Gest
👨‍💻 A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (-6.03%)
Mutual labels:  testing-tools
Pysipp
SIPp for Humans - launch multiple agents with Python
Stars: ✭ 101 (-12.93%)
Mutual labels:  testing-tools
Rails Testing Toolbox
🔧 Tools to help Rails developers test
Stars: ✭ 110 (-5.17%)
Mutual labels:  testing-tools
Cypressautomocker
cypress-based library for capturing APIs and replaying them as mocks
Stars: ✭ 102 (-12.07%)
Mutual labels:  testing-tools
Paraunit
Run PHPUnit tests in parallel
Stars: ✭ 104 (-10.34%)
Mutual labels:  testing-tools
Psrule
Validate infrastructure as code (IaC) and objects using PowerShell rules.
Stars: ✭ 107 (-7.76%)
Mutual labels:  testing-tools
Nose Timer
A timer plugin for nosetests (how much time does every test take?)
Stars: ✭ 116 (+0%)
Mutual labels:  testing-tools
Fakedata
CLI utility for fake data generation
Stars: ✭ 114 (-1.72%)
Mutual labels:  testing-tools

capybara_discoball

Build Status Code Climate

Spin up a rack app just for Capybara.

This is useful for when ShamRack won't cut it: when your JavaScript hits an external service, or you need to load an image or iframe from elsewhere, or in general something outside of your Ruby code needs to talk with an API.

Synopsis

# Use Sinatra, for example
require 'sinatra/base'
require 'capybara_discoball'

# Define a quick Rack app
class FakeMusicDB < Sinatra::Base
  cattr_reader :albums

  get '/musicians/:musician/albums' do |musician|
    <<-XML
    <albums for="#{musician}">
      #{@albums.map { |album| "<album>#{album}</album>" }.join}
    </albums>
    XML
  end
end

# Spin up the Rack app, then update the imaginary library we're
# using to point to the new URL.
Capybara::Discoball.spin(FakeMusicDB) do |server|
  MusicDB.endpoint_url = server.url
end

More details

You can instantiate a Capybara::Discoball::Runner, passing in a factory which will create a Rack app:

FakeMusicDBRunner = Capybara::Discoball::Runner.new(FakeMusicDB) do
  # tests to perform after server boot
end

This gives you back a runner, which you can boot from your features, specs, tests, console, whatever:

FakeMusicDBRunner.boot

These two steps can be merged with the spin class method:

Capybara::Discoball.spin(FakeMusicDB) do
  # tests to perform while server is spinning
end

It is always the case that you need to know the URL for the external API. We provide a way to access that URL; in fact, we offer the whole Capybara::Server for you to play with. In this example, we are using some MusicDB library in the code that knows to hit the .endpoint_url:

FakeMusicDBRunner = Capybara::Discoball::Runner.new(FakeMusicDB) do |server|
  MusicDB.endpoint_url = server.url
end

If no block is provided, the URL is also returned by #spin:

MusicDB.endpoint_url = Capybara::Discoball.spin(FakeMusicDB)

Integrating into your app

All of this means that you must be able to set the endpoint URL. There are two tricky cases:

When the third-party library does not have hooks to set the endpoint URL.

Open the class and add the hooks yourself. This requires understanding the source of the library. Here's an example where the library uses @@endpoint_url everywhere to refer to the endpoint URL:

class MusicDB
  def self.endpoint_url=(endpoint_url)
    @@endpoint_url = endpoint_url
  end
end

When your JavaScript needs to talk to the endpoint URL.

For this you must thread the URL through your app so that the JavaScript can find it:

<% content_for :javascript do %>
  <% javascript_tag do %>
    albumShower = new AlbumShower(<%= MusicDB.endpoint_url.to_json %>);
    albumShower.show();
  <% end %>
<% end %>

class @AlbumShower
  constructor: (@endpointUrl) ->
  show: ->
    $.get(@endpointUrl, (data) -> $('#albums').html(data))

Contributing

See the CONTRIBUTING document. Thank you, contributors!

License

capybara_discoball is Copyright (c) 2012-2018 thoughtbot, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

thoughtbot

capybara_discoball is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects or hire us to help build your product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].