Coder Social home page Coder Social logo

mock-server's Introduction

MockServer

A quick way of mocking an external web service you want to consume.

Usage

You're writing a feature that needs to connect to an external web service (anything served by HTTP). You wonder how to test that. Your options are to stub methods in Net::HTTP and equivalents, but by doing that you are tying yourself to an implementation detail. The ideal thing to do is to lay out an environment where your code can still run, connect to a web server, send out requests and get responses back. Enter MockServer.

class RSSFeedTest < Test::Unit::TestCase
  extend MockServer::Methods

  mock_server {
    get "/feed.xml" do
      <<-EOS
      <?xml version="1.0"?>
      <rss version="2.0">
        <channel>
          <title>A mock website</title>
          <link>http://example.com/</link>
        </channel>
      </rss>
      EOS
    end
  }

  def test_rss_feed
    # YourAwesomeComponent should connect to http://localhost:4000.
    # (you *are* putting those URLs in an environment-aware config file, right?)

    posts = YourAwesomeComponent.load_posts

    assert_equal "A mock website", post.first.channel.title
  end
end

Yes, things happening inside the mock_server call are just a regular Sinatra application. w00t!

License

MIT.

mock-server's People

Contributors

djanowski avatar vangberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mock-server's Issues

Not available on rubygems.

I tried to bundle install this gem off of ruby-gems in my rails app and it doesn't seem to find it. ๐Ÿค”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.