Module: Chicago::Riot::Macros

Defined in:
lib/chicago/riot/macros.rb

Instance Method Summary collapse

Instance Method Details

#asserts_content_type(expected) ⇒ Object



18
19
20
# File 'lib/chicago/riot/macros.rb', line 18

def asserts_content_type(expected)
  asserts("content type is #{expected}") { last_response.headers['Content-type'] }.equals(expected)
end

#asserts_json_response(*args, &block) ⇒ Object

Usage:

asserts_json_response({"foo" => "bar"})
asserts_json_response('{"foo":"bar"}')
asserts_json_response("text/javascript;charset=utf-8", {"foo" => "bar"})
asserts_json_response { {"foo" => @some_value}.to_json }
asserts_json_response("text/javascript;charset=utf-8") { {"foo" => @some_value}.to_json }


42
43
44
45
46
47
48
49
50
# File 'lib/chicago/riot/macros.rb', line 42

def asserts_json_response(*args, &block)
  unless block_given?
    json = args.pop
    json = json.to_json unless json.instance_of?(String)
  end
  asserts("response body has JSON") { last_response.body }.equals(&(block || lambda {json}))

  asserts_content_type(args.empty? ? 'application/json;charset=utf-8' : args.shift)
end

#asserts_location(expected_path) ⇒ Object



30
31
32
33
34
# File 'lib/chicago/riot/macros.rb', line 30

def asserts_location(expected_path)
  asserts("location matches #{expected_path}") do
    last_response.headers["Location"]
  end.matches(expected_path)
end

#asserts_redirected_to(expected_path) ⇒ Object

Usage:

assert_redirected_to '/foo/bar'
assert_redirected_to %r[foo/bar]


55
56
57
58
# File 'lib/chicago/riot/macros.rb', line 55

def asserts_redirected_to(expected_path)
  asserts_response_status 302
  asserts_location expected_path
end

#asserts_response(method = nil) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/chicago/riot/macros.rb', line 6

def asserts_response(method=nil)
  if method
    asserts("response #{method}") { last_response.send(method) }
  else
    asserts("response") { last_response }
  end
end

#asserts_response_body(expected) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/chicago/riot/macros.rb', line 22

def asserts_response_body(expected)
  if (expected.kind_of?(Regexp))
    asserts("response body matches #{expected.inspect}") { last_response.body }.matches(expected)
  else
    asserts("response body is exactly #{expected.inspect}") { last_response.body }.equals(expected)
  end
end

#asserts_response_status(expected) ⇒ Object



14
15
16
# File 'lib/chicago/riot/macros.rb', line 14

def asserts_response_status(expected)
  asserts("response status is #{expected}") { last_response.status }.equals(expected)
end