httparrot 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,4 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .buildpath
6
- .project
6
+ .project
7
+ *.lnk
data/Gemfile CHANGED
@@ -6,3 +6,7 @@ gemspec
6
6
  platforms :jruby do
7
7
  gem 'jruby-openssl'
8
8
  end
9
+
10
+ platforms :mingw do
11
+ gem 'i18n'
12
+ end
data/httparrot.gemspec CHANGED
@@ -5,8 +5,8 @@ require "httparrot/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "httparrot"
7
7
  s.version = HTTParrot::VERSION
8
- s.authors = ["Brandon Dewitt"]
9
- s.email = ["brandonsdewitt@gmail.com"]
8
+ s.authors = ["Brandon Dewitt", "lawrence mcalpin"]
9
+ s.email = ["brandonsdewitt+httparrot@gmail.com"]
10
10
  s.homepage = ""
11
11
  s.summary = %q{Mock Server for testing HTTP anything!}
12
12
  s.description = %q{helps cut through the clutter of HTTP testing}
@@ -29,9 +29,9 @@ module HTTParrot
29
29
  }.merge(HTTParrot::Config.config).merge(opts)
30
30
 
31
31
  # hard to believe, but it's true, some people still use Windows! like me.
32
- isWindows = RUBY_PLATFORM.downcase =~ /mswin|windows|mingw/i
32
+ is_windows = RUBY_PLATFORM =~ /mswin|windows|mingw/i
33
33
  quiet_options = {
34
- :Logger => WEBrick::Log::new(isWindows ? "nul" : "/dev/null", 7),
34
+ :Logger => WEBrick::Log::new(is_windows ? "nul" : "/dev/null", 7),
35
35
  :AccessLog => []
36
36
  }
37
37
 
@@ -88,15 +88,17 @@ module HTTParrot
88
88
  @parent_thread.raise e
89
89
  end
90
90
 
91
- def register(http_method, method_key, response, call_with_env = false)
91
+ def register(http_method, method_key, response, opts={})
92
92
  http_method = http_method.to_s.downcase.to_sym
93
93
  raise "http_method in register must be one of [:get, :post, :head, :delete] : #{http_method}" if ![:get, :post, :head, :delete].include?(http_method)
94
94
 
95
+ call_with_env = opts[:call_with_env] || false
95
96
  response_handler = OpenStruct.new({
96
97
  :method_key => method_key,
97
98
  :response => response,
98
99
  :env? => call_with_env,
99
- :response_count => 0
100
+ :response_count => 0,
101
+ :options => opts
100
102
  })
101
103
 
102
104
  case
@@ -143,6 +145,9 @@ module HTTParrot
143
145
  # Increment the number of times a handler was used (for asserting usage)
144
146
  def increment_return(handler)
145
147
  handler.response_count = handler.response_count + 1
148
+ if handler.options then
149
+ sleep handler.options[:delay] if handler.options[:delay]
150
+ end
146
151
  return handler.response
147
152
  end
148
153
 
@@ -1,3 +1,3 @@
1
1
  module HTTParrot
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/spec/server_spec.rb CHANGED
@@ -182,6 +182,15 @@ describe HTTParrot::Server do
182
182
  handlers[:get].should_not be_empty
183
183
  handlers[:post].should be_empty
184
184
  end
185
+
186
+ it "can simulate slow connections" do
187
+ handler = @server.register(:get, ["/widget", /widget/], @widget.to_rack, :delay => 0.5)
188
+
189
+ # stub sleep
190
+ @server.stub!(:sleep)
191
+ @server.should_receive(:sleep).with(0.5)
192
+ @server.send(:increment_return, handler)
193
+ end
185
194
 
186
195
  it "raises error when handler type cannot be inferred" do
187
196
  expect{ @server.register(:get, 1, @widget.to_rack) }.to raise_error(/callable/)
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparrot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brandon Dewitt
9
+ - lawrence mcalpin
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
@@ -13,7 +14,7 @@ date: 2012-02-16 00:00:00.000000000Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
16
- requirement: &7158800 !ruby/object:Gem::Requirement
17
+ requirement: &11870200 !ruby/object:Gem::Requirement
17
18
  none: false
18
19
  requirements:
19
20
  - - =
@@ -21,10 +22,10 @@ dependencies:
21
22
  version: '2.7'
22
23
  type: :development
23
24
  prerelease: false
24
- version_requirements: *7158800
25
+ version_requirements: *11870200
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: rake
27
- requirement: &7157260 !ruby/object:Gem::Requirement
28
+ requirement: &11868780 !ruby/object:Gem::Requirement
28
29
  none: false
29
30
  requirements:
30
31
  - - ! '>='
@@ -32,10 +33,10 @@ dependencies:
32
33
  version: '0'
33
34
  type: :development
34
35
  prerelease: false
35
- version_requirements: *7157260
36
+ version_requirements: *11868780
36
37
  - !ruby/object:Gem::Dependency
37
38
  name: rack
38
- requirement: &7156240 !ruby/object:Gem::Requirement
39
+ requirement: &11867740 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ! '>='
@@ -43,10 +44,10 @@ dependencies:
43
44
  version: '0'
44
45
  type: :runtime
45
46
  prerelease: false
46
- version_requirements: *7156240
47
+ version_requirements: *11867740
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: activesupport
49
- requirement: &7153880 !ruby/object:Gem::Requirement
50
+ requirement: &11866680 !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
52
53
  - - ! '>='
@@ -54,10 +55,10 @@ dependencies:
54
55
  version: '0'
55
56
  type: :runtime
56
57
  prerelease: false
57
- version_requirements: *7153880
58
+ version_requirements: *11866680
58
59
  description: helps cut through the clutter of HTTP testing
59
60
  email:
60
- - brandonsdewitt@gmail.com
61
+ - brandonsdewitt+httparrot@gmail.com
61
62
  executables: []
62
63
  extensions: []
63
64
  extra_rdoc_files: []
@@ -96,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
97
  version: '0'
97
98
  segments:
98
99
  - 0
99
- hash: 3040372420492904565
100
+ hash: -2796158794864830420
100
101
  required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  none: false
102
103
  requirements:
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  segments:
107
108
  - 0
108
- hash: 3040372420492904565
109
+ hash: -2796158794864830420
109
110
  requirements: []
110
111
  rubyforge_project: httparrot
111
112
  rubygems_version: 1.8.10