/
request_profile_spec.rb
63 lines (47 loc) · 2.05 KB
/
request_profile_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe RequestProfile do
describe "initialization" do
it "should have assigned normalized uri" do
WebMock::Util::URI.should_receive(:normalize_uri).and_return("www.google.kom")
profile = RequestProfile.new(:get, "www.google.com")
profile.uri.should == "www.google.kom"
end
it "should have assigned uri without normalization if uri is URI" do
WebMock::Util::URI.should_not_receive(:normalize_uri)
uri = Addressable::URI.parse("www.google.com")
profile = RequestProfile.new(:get, uri)
profile.uri.should == uri
end
it "should have assigned normalized headers" do
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
RequestProfile.new(:get, "www.google.com", :headers => {'A' => 'a'}).headers.should == {'B' => 'b'}
end
it "should have assigned body" do
RequestProfile.new(:get, "www.google.com", :body => "abc").
body.should == RequestProfile::Body.new("abc")
end
end
it "should report string describing itself" do
RequestProfile.new(:get, "www.google.com",
:body => "abc", :headers => {'A' => 'a', 'B' => 'b'}).to_s.should ==
"GET http://www.google.com/ with body 'abc' with headers {'A'=>'a', 'B'=>'b'}"
end
describe "with" do
before(:each) do
@request_profile = RequestProfile.new(:get, "www.google.com")
end
it "should assign body to request profile" do
@request_profile.with(:body => "abc")
@request_profile.body.should == RequestProfile::Body.new("abc")
end
it "should have the same body" do
@request_profile.with(:body => "abc")
@request_profile.body.should == RequestProfile::Body.new("abc")
end
it "should assign normalized headers to request profile" do
WebMock::Util::Headers.should_receive(:normalize_headers).with('A' => 'a').and_return('B' => 'b')
@request_profile.with(:headers => {'A' => 'a'})
@request_profile.headers.should == {'B' => 'b'}
end
end
end