webmachine-test 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,9 +52,8 @@ module Webmachine
52
52
  end
53
53
 
54
54
  def do_request(method, uri, options)
55
+ uri = "http://localhost#{uri}" unless uri =~ %r(^https?://)
55
56
  uri = URI.parse(uri)
56
- uri.scheme ||= 'http'
57
- uri.host ||= 'localhost'
58
57
 
59
58
  add_query_params(uri, options[:params])
60
59
 
@@ -1,5 +1,5 @@
1
1
  module Webmachine
2
2
  module Test
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
@@ -1,5 +1,3 @@
1
- require 'webmachine'
2
-
3
1
  class TestResource < Webmachine::Resource
4
2
  def content_types_provided
5
3
  [['text/plain', :to_text]]
@@ -0,0 +1,9 @@
1
+ class TraceableResource < Webmachine::Resource
2
+ def trace?
3
+ true
4
+ end
5
+
6
+ def to_html
7
+ "<html><head><title>Hi</title><body><p>html_hi</p></body></html>"
8
+ end
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,12 +3,18 @@ require 'bundler/setup'
3
3
 
4
4
  require 'webmachine/application'
5
5
  require 'webmachine/test'
6
+ require 'webmachine'
7
+
6
8
  require 'fixtures/test_resource'
9
+ require 'fixtures/traceable_resource'
7
10
 
8
11
  module WebmachineTestApplication
9
12
  def app
10
- @app ||= Webmachine::Application.new.tap do |test_app|
11
- test_app.add_route(['*'], TestResource)
13
+ @app ||= Webmachine::Application.new do |test_app|
14
+ test_app.routes do
15
+ add ['traceme'], TraceableResource
16
+ add ['*'], TestResource
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -17,16 +17,30 @@ describe Webmachine::Test::Session do
17
17
  end
18
18
 
19
19
  describe "#response" do
20
- it "returns the Webmachine::Response object" do
21
- get '/'
22
- response.should be_a(Webmachine::Response)
23
- end
24
-
25
20
  context "without a request" do
26
21
  it "raises an exception" do
27
22
  expect { response }.to raise_error(Webmachine::Test::Error)
28
23
  end
29
24
  end
25
+
26
+ context "with an untraceable resource" do
27
+ before { get '/' }
28
+
29
+ subject { response }
30
+
31
+ it { should be_a(Webmachine::Response) }
32
+ its(:code) { should eql(200) }
33
+ its(:body) { should eql('OK') }
34
+ end
35
+
36
+ context "with a traceable resource" do
37
+ before { get '/traceme' }
38
+
39
+ subject { response }
40
+
41
+ its(:code) { should eql(200) }
42
+ its(:body) { should include('html_hi') }
43
+ end
30
44
  end
31
45
 
32
46
  shared_examples_for "a HTTP verb" do
@@ -50,12 +64,12 @@ describe Webmachine::Test::Session do
50
64
  context "with an incomplete URI" do
51
65
  it "sets the correct host header" do
52
66
  send verb, '/foo'
53
- request.headers['Host'].should == 'localhost'
67
+ request.headers['Host'].should == 'localhost:80'
54
68
  end
55
69
  end
56
70
 
57
71
  it "accepts query parameters in the path" do
58
- send verb,'/?lang=en&foo=bar'
72
+ send verb, '/?lang=en&foo=bar'
59
73
  request.query['lang'].should == 'en'
60
74
  request.query['foo'].should == 'bar'
61
75
  end
@@ -73,7 +87,7 @@ describe Webmachine::Test::Session do
73
87
  end
74
88
 
75
89
  it "encodes the query key and value." do
76
- send verb, '/', :params => { "foo=" => "bar=" }
90
+ send verb, '/', :params => {"foo=" => "bar="}
77
91
  request.uri.query.should == "foo%3D=bar%3D"
78
92
  end
79
93
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmachine-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-28 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: webmachine
@@ -43,6 +43,7 @@ files:
43
43
  - lib/webmachine/test/session.rb
44
44
  - lib/webmachine/test/version.rb
45
45
  - spec/fixtures/test_resource.rb
46
+ - spec/fixtures/traceable_resource.rb
46
47
  - spec/spec_helper.rb
47
48
  - spec/webmachine/test/session_spec.rb
48
49
  - webmachine-test.gemspec
@@ -60,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
61
  version: '0'
61
62
  segments:
62
63
  - 0
63
- hash: -2796034837073697484
64
+ hash: 152134927568683489
64
65
  required_rubygems_version: !ruby/object:Gem::Requirement
65
66
  none: false
66
67
  requirements:
@@ -69,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  version: '0'
70
71
  segments:
71
72
  - 0
72
- hash: -2796034837073697484
73
+ hash: 152134927568683489
73
74
  requirements: []
74
75
  rubyforge_project: webmachine-test
75
76
  rubygems_version: 1.8.24