Skip to content

Commit

Permalink
refactor even tighter. too tight now?
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdempsey committed Nov 13, 2008
1 parent 2aa1b70 commit 1a85940
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions spec/requests/gists_spec.rb
Expand Up @@ -3,15 +3,17 @@
# bring in the constants so we can use NotFound, etc, instead of Merb::ControllerExceptions::NotFound
include Merb::ControllerExceptions

def it_should_return(content_type)
it "should have content type #{content_type}" do
@response.should have_content_type(content_type)
def should_return(hash)
if hash[:content_type]
it "should have content type #{hash[:content_type]}" do
@response.should have_content_type(hash[:content_type])
end
end
end

def it_should_respond_with(status_code)
it "should render a #{status_code} (#{status_code.status})" do
@response.status.should == status_code.status
if hash[:status_code]
it "should render a #{hash[:status_code]} (#{hash[:status_code].status})" do
@response.status.should == hash[:status_code].status
end
end
end

Expand All @@ -20,9 +22,7 @@ def it_should_respond_with(status_code)
@response = request("/gists.json")
end

it_should_respond_with OK

it_should_return :json
should_return :content_type => :json, :status_code => OK
end

describe "#show" do
Expand All @@ -32,19 +32,15 @@ def it_should_respond_with(status_code)
@response = request("/gists/#{gist.id}.json")
end

it_should_respond_with OK

it_should_return :json
should_return :content_type => :json, :status_code => OK
end

describe "unsuccessful" do
before do
@response = request("/gists/0.json")
end

it_should_respond_with NotFound

it_should_return :json
should_return :content_type => :json, :status_code => NotFound
end
end

Expand All @@ -56,9 +52,7 @@ def it_should_respond_with(status_code)
:method => "POST") # we can't use :post; look in the code, it checks for "POST"
end

it_should_respond_with Created

it_should_return :json
should_return :content_type => :json, :status_code => Created
end

describe "unsuccessful" do
Expand All @@ -71,9 +65,7 @@ def it_should_respond_with(status_code)
@response.body.to_s.should include("Url must not be blank")
end

it_should_respond_with BadRequest

it_should_return :json
should_return :content_type => :json, :status_code => BadRequest
end
end

Expand All @@ -96,9 +88,7 @@ def it_should_respond_with(status_code)
@body['url'].should == @new_url
end

it_should_respond_with Accepted

it_should_return :json
should_return :content_type => :json, :status_code => Accepted
end

describe "unsuccessful" do
Expand All @@ -124,9 +114,7 @@ def it_should_respond_with(status_code)
@body['exceptions'].map {|exception| exception['message']}.should include("Url must not be blank")
end

it_should_respond_with BadRequest

it_should_return :json
should_return :content_type => :json, :status_code => BadRequest
end
end

Expand All @@ -146,9 +134,7 @@ def it_should_respond_with(status_code)
@response.should have_body('')
end

it_should_respond_with NoContent

it_should_return :json
should_return :content_type => :json, :status_code => NoContent
end

describe "unsuccessful" do
Expand All @@ -162,8 +148,6 @@ def it_should_respond_with(status_code)
body['exceptions'].map {|exception| exception['message']}.should include("Merb::ControllerExceptions::NotFound")
end

it_should_respond_with NotFound

it_should_return :json
should_return :content_type => :json, :status_code => NotFound
end
end

0 comments on commit 1a85940

Please sign in to comment.