Permalink
Browse files

Clean things up

  • Loading branch information...
1 parent 3fe3480 commit ebf5cba06edf811cd62c78d33309d9c04ec0c28e @lmarburger committed Oct 21, 2010
Showing with 32 additions and 33 deletions.
  1. +0 −5 Gemfile.lock
  2. +11 −4 features/smog.feature
  3. +17 −15 lib/smog/cli.rb
  4. +4 −9 smog.gemspec
View
@@ -2,9 +2,7 @@ PATH
remote: .
specs:
smog (0.0.2)
- fattr
main
- net-http-digest_auth
GEM
remote: http://rubygems.org/
@@ -30,7 +28,6 @@ GEM
main (4.2.0)
arrayfields (>= 4.7.4)
fattr (>= 2.1.0)
- net-http-digest_auth (1.0)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
@@ -49,8 +46,6 @@ PLATFORMS
DEPENDENCIES
aruba
cucumber
- fattr
main
- net-http-digest_auth
rspec
smog!
View
@@ -8,6 +8,16 @@ Feature: Smog
"""
smog auth=test@example.com:pass "http://my.cloudapp.local/items?page=1&per_page=5"
"""
+ #Then the output should be exactly:
+ #"""
+ #curl -I -s --digest -u test@example.com:pass -H "Accept: application/json" "http://my.cloudapp.local/items?page=1&per_page=5"
+ #HTTP/1.1 401 Authorization Required
+ #HTTP/1.1 200 OK
+
+ #curl -I -s --digest -u test@example.com:pass -H "Accept: application/json" -H "If-None-Match: \"c6b5d4a0589c53bf1d8326422fc33f57\"" -H "If-Modified-Since: Fri, 15 Oct 2010 14:46:14 GMT"
+ #HTTP/1.1 401 Authorization Required
+ #HTTP/1.1 304 Not Modified
+ #"""
Then the output should contain:
"""
curl -I -s --digest -u test@example.com:pass -H "Accept: application/json" "http://my.cloudapp.local/items?page=1&per_page=5"
@@ -16,10 +26,7 @@ Feature: Smog
"""
And the output should match:
"""
- curl -I -s --digest -u test@example.com:pass -H "If-None-Match: \\"[^"]+\\"" -H "If-Modified-Since: [\w,: ]+" -H "Accept: application/json" "http://my.cloudapp.local/items\?page=1&per_page=5"
- """
- And the output should contain:
- """
+ curl -I -s --digest -u test@example.com:pass -H "Accept: application/json" -H "If-None-Match: \\"[^"]+\\"" -H "If-Modified-Since: [\w,: ]+" "http://my.cloudapp.local/items\?page=1&per_page=5"
HTTP/1.1 401 Authorization Required
HTTP/1.1 304 Not Modified
"""
View
@@ -14,10 +14,10 @@
def run
2.times do
- new_command = curl
+ command = build_curl
- @last_response = %x[#{ new_command }]
- puts_response new_command, @last_response
+ @last_response = %x(#{ command })
+ puts_response command, @last_response
end
end
@@ -30,10 +30,11 @@ def run
# -H "If-None-Match: \"05122c59185e3bcf8b9a1976d46c2040\""
# -H "If-Modified-Since: Tue, 05 Oct 2010 13:44:39 GMT"
# "http://my.cloudapp.local/items?page=1&per_page=5"
- def curl
- [ 'curl -I -s' ].tap do |command|
- command << "--digest -u #{ params[:auth].value }"
-
+ def build_curl
+ [ 'curl -I -s',
+ "--digest -u #{ params[:auth].value }",
+ header('Accept', 'application/json')
+ ].tap do |command|
if etag
command << header('If-None-Match', %{\\"#{ etag }\\"})
end
@@ -42,8 +43,7 @@ def curl
command << header('If-Modified-Since', last_modified)
end
- command << header('Accept', 'application/json')
- command << "#{ params[:url].value.inspect }\n"
+ command << params[:url].value.inspect
end.join ' '
end
@@ -52,19 +52,21 @@ def header(name, value)
end
def etag
- return unless @last_response
-
- etag = @last_response.match(/ETag: "(.*)"/)[1].chomp
+ response_header /ETag: "(.*)"/
end
def last_modified
+ response_header /Last-Modified: (.*)/
+ end
+
+ def response_header(match_header)
return unless @last_response
- last_modified = @last_response.match(/Last-Modified: (.*)/)[1].chomp
+ @last_response.match(match_header)[1].chomp
end
- def puts_response(curl, full_response)
- puts curl
+ def puts_response(command, full_response)
+ puts command
full_response.split("\r\n\r\n").each do |response|
status = response.split("\r\n").first
View
@@ -12,19 +12,14 @@ Gem::Specification.new do |s|
s.summary = %q{Test the CloudApp API from the command line}
s.description = %q{Smog simply outputs a curl command to use to test the CloudApp API}
- s.required_rubygems_version = ">= 1.3.6"
-
s.add_dependency "main"
- s.add_dependency "fattr"
- s.add_dependency "net-http-digest_auth"
s.add_development_dependency "rspec"
s.add_development_dependency "cucumber"
s.add_development_dependency "aruba"
- s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = %w(smog)
- s.default_executable = "smog"
- s.require_paths = ["lib"]
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
end

0 comments on commit ebf5cba

Please sign in to comment.