Class: Shoulda::ActionController::Matchers::RespondWithContentTypeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(content_type) ⇒ RespondWithContentTypeMatcher

Returns a new instance of RespondWithContentTypeMatcher.



26
27
28
29
30
31
32
# File 'lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb', line 26

def initialize(content_type)
  @content_type = if content_type.is_a?(Symbol)
    lookup_by_extension(content_type)
  else
    content_type
  end
end

Instance Method Details

#descriptionObject



34
35
36
# File 'lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb', line 34

def description
  "respond with content type of #{@content_type}"
end

#failure_messageObject



47
48
49
# File 'lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb', line 47

def failure_message
  "Expected #{expectation}"
end

#matches?(controller) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb', line 38

def matches?(controller)
  @controller = controller
  if @content_type.is_a?(Regexp)
    response_content_type =~ @content_type
  else
    response_content_type == @content_type
  end
end

#negative_failure_messageObject



51
52
53
# File 'lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb', line 51

def negative_failure_message
  "Did not expect #{expectation}"
end