Class: Peck::Rails::Controller::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/peck_on_rails/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Body

Returns a new instance of Body.


116
117
118
# File 'lib/peck_on_rails/controller.rb', line 116

def initialize(response)
  @response = response
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)

144
145
146
# File 'lib/peck_on_rails/controller.rb', line 144

def blank?
  @response.body.blank?
end

#documentObject


120
121
122
123
124
125
126
# File 'lib/peck_on_rails/controller.rb', line 120

def document
  if defined?(Nokogiri)
    @document ||= Nokogiri::HTML.parse(@response.body)
  else
    raise RuntimeError, "Please install Nokogiri to use the CSS or Xpath matchers (gem install nokogiri)"
  end
end

#inspectObject


148
149
150
# File 'lib/peck_on_rails/controller.rb', line 148

def inspect
  "#<html body=\"#{@response.body}\">"
end

#jsonObject


128
129
130
131
132
133
134
# File 'lib/peck_on_rails/controller.rb', line 128

def json
  if defined?(JSON)
    @json ||= JSON.parse(@response.body)
  else
    raise RuntimeError, "Please install a JSON gem to use the json accessor (gem install json)"
  end
end

#match_css?(query) ⇒ Boolean

Returns:

  • (Boolean)

136
137
138
# File 'lib/peck_on_rails/controller.rb', line 136

def match_css?(query)
  !document.css(query).empty?
end

#match_xpath?(query) ⇒ Boolean

Returns:

  • (Boolean)

140
141
142
# File 'lib/peck_on_rails/controller.rb', line 140

def match_xpath?(query)
  !document.xpath(query).empty?
end