crow 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +15 -0
  2. data/lib/crow.rb +12 -3
  3. data/spec/get_spec.rb +12 -3
  4. metadata +4 -3
data/README.markdown ADDED
@@ -0,0 +1,15 @@
1
+ Crow
2
+ ====
3
+
4
+ Easy endpoints for api mocking
5
+
6
+ Usage
7
+ -----
8
+
9
+ Make a new instance with `Crow.new( path_to_your_fixtures )`
10
+
11
+ You'll probably want to use Artifice (or ShamRack). Using with Artifice is easy, just do `Artifice.activate_with Crow.new(path)`
12
+
13
+ Your fixures directory should have a folder for get, post, put, and delete. Right now Crow only does gets, but will do the REST shortly (snicker).
14
+
15
+
data/lib/crow.rb CHANGED
@@ -1,11 +1,20 @@
1
1
  require 'sinatra'
2
2
  class Crow < Sinatra::Base
3
- def initialize(root_path)
4
- super
3
+ def initialize(root_path, opts={})
4
+ super(nil)
5
5
  @root_path = root_path
6
+ @opts = opts
6
7
  end
7
8
 
8
9
  get "/*" do |path|
9
- File.read File.join(@root_path, 'get', path)
10
+ fixture_path = File.join(@root_path, 'get', path)
11
+ begin
12
+ response = File.read fixture_path
13
+ rescue
14
+ @response.status = 500
15
+ response = "Couldn't find: #{fixture_path}"
16
+ puts response if @opts[:verbose]
17
+ end
18
+ response
10
19
  end
11
20
  end
data/spec/get_spec.rb CHANGED
@@ -1,12 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
+ def get(uri)
4
+ HTTParty.get(uri)
5
+ end
6
+
3
7
  describe Crow, "get" do
4
8
  it "should map top level uris to fixture files" do
5
- HTTParty.get("http://whatever/simple_get.txt").should == "it worked\n"
9
+ get("http://whatever/simple_get.txt").should == "it worked\n"
6
10
  end
7
11
 
8
12
  it "should work with nested routes" do
9
- HTTParty.get("http://whatever/people/1.json").should == "{'name': 'will'}\n"
13
+ get("http://whatever/people/1.json").should == "{'name': 'will'}\n"
14
+ end
15
+
16
+ it "should let us know when the fixture isn't found" do
17
+ response = get("http://whatever/this/is/not/a/fixture")
18
+ response.should =~ /Couldn't find/
19
+ response.code.should == 500
10
20
  end
11
-
12
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crow
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Will Leinweber
@@ -44,6 +44,7 @@ files:
44
44
  - lib/crow.rb
45
45
  - spec/get_spec.rb
46
46
  - spec/spec_helper.rb
47
+ - README.markdown
47
48
  has_rdoc: true
48
49
  homepage: http://github.com/will/crow
49
50
  licenses: []