spec_helper.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. require "rubygems"
  2. require "bundler/setup"
  3. require "rack"
  4. require "rspec"
  5. Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
  6. require "rack/test"
  7. require File.dirname(__FILE__) + "/fixtures/fake_app"
  8. RSpec.configure do |config|
  9. config.mock_with :rspec
  10. config.include Rack::Test::Methods
  11. def app
  12. Rack::Lint.new(Rack::Test::FakeApp.new)
  13. end
  14. def check(*args)
  15. end
  16. end
  17. shared_examples_for "any #verb methods" do
  18. it "requests the URL using VERB" do
  19. send(verb, "/")
  20. check last_request.env["REQUEST_METHOD"].should == verb.upcase
  21. last_response.should be_ok
  22. end
  23. it "uses the provided env" do
  24. send(verb, "/", {}, { "HTTP_USER_AGENT" => "Rack::Test" })
  25. last_request.env["HTTP_USER_AGENT"].should == "Rack::Test"
  26. end
  27. it "yields the response to a given block" do
  28. yielded = false
  29. send(verb, "/") do |response|
  30. response.should be_ok
  31. yielded = true
  32. end
  33. yielded.should be_true
  34. end
  35. it "sets the HTTP_HOST header with port" do
  36. send(verb, "http://example.org:8080/uri")
  37. last_request.env["HTTP_HOST"].should == "example.org:8080"
  38. end
  39. it "sets the HTTP_HOST header without port" do
  40. send(verb, "/uri")
  41. last_request.env["HTTP_HOST"].should == "example.org"
  42. end
  43. context "for a XHR" do
  44. it "sends XMLHttpRequest for the X-Requested-With header" do
  45. send(verb, "/", {}, { :xhr => true })
  46. last_request.env["HTTP_X_REQUESTED_WITH"].should == "XMLHttpRequest"
  47. last_request.should be_xhr
  48. end
  49. end
  50. end