Permalink
Browse files

Remove 'respond_with_content_type' matcher

* See issue #252
  • Loading branch information...
1 parent c4413a4 commit 47ffcdbf38e183e87ffc4a8c455e71654a25380e @mxie mxie committed with mxie Mar 15, 2013
View
1 lib/shoulda/matchers/action_controller.rb
@@ -3,7 +3,6 @@
require 'shoulda/matchers/action_controller/set_the_flash_matcher'
require 'shoulda/matchers/action_controller/render_with_layout_matcher'
require 'shoulda/matchers/action_controller/respond_with_matcher'
-require 'shoulda/matchers/action_controller/respond_with_content_type_matcher'
require 'shoulda/matchers/action_controller/set_session_matcher'
require 'shoulda/matchers/action_controller/route_matcher'
require 'shoulda/matchers/action_controller/redirect_to_matcher'
View
83 lib/shoulda/matchers/action_controller/respond_with_content_type_matcher.rb
@@ -1,83 +0,0 @@
-require 'active_support/deprecation'
-
-module Shoulda # :nodoc:
- module Matchers
- module ActionController # :nodoc:
-
- # Ensures a controller responded with expected 'response' content type.
- #
- # You can pass an explicit content type such as 'application/rss+xml'
- # or its symbolic equivalent :rss
- # or a regular expression such as /rss/
- #
- # Example:
- #
- # it { should respond_with_content_type(:xml) }
- # it { should respond_with_content_type(:csv) }
- # it { should respond_with_content_type(:atom) }
- # it { should respond_with_content_type(:yaml) }
- # it { should respond_with_content_type(:text) }
- # it { should respond_with_content_type('application/rss+xml') }
- # it { should respond_with_content_type(/json/) }
- def respond_with_content_type(content_type)
- RespondWithContentTypeMatcher.new(content_type)
- end
-
- class RespondWithContentTypeMatcher # :nodoc:
- def initialize(content_type)
- ActiveSupport::Deprecation.warn 'The respond_with_content_type matcher is deprecated and will be removed in 2.0'
- @content_type = look_up_content_type(content_type)
- end
-
- def description
- "respond with content type of #{@content_type}"
- end
-
- def matches?(controller)
- @controller = controller
- content_type_matches_regexp? || content_type_matches_string?
- end
-
- def failure_message_for_should
- "Expected #{expectation}"
- end
-
- def failure_message_for_should_not
- "Did not expect #{expectation}"
- end
-
- protected
-
- def content_type_matches_regexp?
- if @content_type.is_a?(Regexp)
- response_content_type =~ @content_type
- end
- end
-
- def content_type_matches_string?
- response_content_type == @content_type
- end
-
- def response_content_type
- @controller.response.content_type.to_s
- end
-
- def look_up_by_extension(extension)
- Mime::Type.lookup_by_extension(extension.to_s).to_s
- end
-
- def look_up_content_type(content_type)
- if content_type.is_a?(Symbol)
- look_up_by_extension(content_type)
- else
- content_type
- end
- end
-
- def expectation
- "content type to be #{@content_type}, but was #{response_content_type}"
- end
- end
- end
- end
-end
View
31 spec/shoulda/matchers/action_controller/respond_with_content_type_matcher_spec.rb
@@ -1,31 +0,0 @@
-require 'spec_helper'
-
-describe Shoulda::Matchers::ActionController::RespondWithContentTypeMatcher do
- it 'generates the correct description' do
- expected = 'respond with content type of application/xml'
-
- respond_with_content_type(:xml).description.should == expected
- end
-
- it 'accepts responding with content type as symbol' do
- xml_controller.should respond_with_content_type(:xml)
- end
-
- it 'accepts responding with qualified MIME-style content type' do
- xml_controller.should respond_with_content_type('application/xml')
- end
-
- it 'accepts responding with a regex matching the content type' do
- xml_controller.should respond_with_content_type(/xml/)
- end
-
- it 'rejects responding with another content type' do
- xml_controller.should_not respond_with_content_type(:json)
- end
-
- def xml_controller
- build_response do
- render :xml => { :user => 'thoughtbot' }.to_xml
- end
- end
-end

0 comments on commit 47ffcdb

Please sign in to comment.