RSpec extension for HTTP request
require 'httpspec_simple'
base_url 'http://kozy4324.github.io'
describe request('/') do
it { should be_http_ok }
it { should respond_within(2).seconds }
it { should retrieve_body_including '<title>L4L</title>' }
end
describe request('/blog/archives/') do
it { should be_http_ok }
it { should respond_within(2).seconds }
it { should retrieve_body_including '<title>Blog Archive - L4L</title>' }
end
$ rspec -f d
http://kozy4324.github.io/
should be http ok
should respond within 2 seconds (got 0.122 seconds)
should retrieve body including "<title>L4L</title>"
http://kozy4324.github.io/blog/archives/
should be http ok
should respond within 2 seconds (got 0.111 seconds)
should retrieve body including "<title>Blog Archive - L4L</title>"
Example passes if response is 200 ok
Example passes if response is 301 or 302
Example passes if response is 301 and Location
response header has a value which equals expected url
Example passes if response is 302 and Location
response header has a value which equals expected url
Example passes if response is 404
Example passes if response is 503
Example passes if response time is less than n seconds
Example passes if response body include the passed string
Example passes if response body match the passed regexp
Do request
option key | type | description |
---|---|---|
:retry | Integer | when the response code is {40x,50x} or the timeout occurs, retry request the specific times, default value is 0 |
:timeout | Integer | set to Net::HTTP's open_timeout and read_timeout |
:headers | Hash | set to the request header |
:basic_auth | Array | basic auth user and password(ex. ['user', 'passwd'] ) |
Prepend to the url string passed to following request
method
configure the global setting as request()
's opt argument
HttpspecSimple::Request.configure {|config|
config.retry = 3
config.timeout = 15
config.headers = {"user-agent" => "my-agent"}
config.basic_auth = ['user', 'passwd']
}
clear all configuration set by HttpspecSimple::Request.configure
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request