Skip to content

Instantly share code, notes, and snippets.

@tosch
Created July 30, 2010 07:44
Show Gist options
  • Save tosch/500101 to your computer and use it in GitHub Desktop.
Save tosch/500101 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../spec_helper'
describe "GET /_ruote/participants" do
after :each do
unless RuoteKit.engine.nil?
RuoteKit.engine.storage.purge! unless RuoteKit.engine.storage.nil?
RuoteKit.shutdown_engine( true )
end
end
describe "without any participant" do
before :each do
RuoteKit.configure { |conf| }
RuoteKit.run_engine!
end
it "should give an empty list (HTML)" do
get "/_ruote/participants"
last_response.should be_ok
end
it "should give an empty array (JSON)" do
get "/_ruote/participants.json"
last_response.should be_ok
body = last_response.json_body
body.should have_key("participants")
body["participants"].should be_empty
end
end
describe "with participant" do
before :each do
RuoteKit.configure { |conf| conf.register { catchall } }
RuoteKit.run_engine!
end
it "should give participant information back (HTML)" do
get "/_ruote/participants"
last_response.should be_ok
end
it "should give participant information back (JSON)" do
get "/_ruote/participants.json"
last_response.should be_ok
body = last_response.json_body
body["participants"].should_not be_empty
end
end
end
describe "GET /_ruote/participants/:name", :type => :with_engine do
describe "without registered participants" do
before :each do
RuoteKit.configure { |conf| }
RuoteKit.run_engine!
end
it "should 404 correctly (HTML)" do
get "/_ruote/participants/foo"
last_response.should_not be_ok
last_response.status.should be(404)
last_response.should match(/Resource not found/)
end
it "should 404 correctly (JSON)" do
get "/_ruote/participants/foo.json"
last_response.should_not be_ok
last_response.status.should be(404)
last_response.json_body.keys.should include("error")
last_response.json_body['error'].should == { "code" => 404, "message" => "Resource not found" }
end
end
describe "with registered participants" do
before :each do
@name = 'foo'
RuoteKit.configure do |conf|
conf.register do
participant @name, Ruote::NoOpParticipant
catchall
end
end
RuoteKit.run_engine!
end
it "should give participant information back (HTML)" do
get "/_ruote/participants/#{@name}"
last_response.should be_ok
end
it "should give process information back (JSON)" do
get "/_ruote/participants/#{@name}.json"
last_response.should be_ok
body = last_response.json_body
body.should have_key('participant')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment