require_relative "./helpers" describe BigBench::Fragment do before(:each) do @benchmark = BigBench::Benchmark::Benchmark.new("a test benchmark", "http://localhost:3001", {}){} @benchmark.start = Time.now end it "should parse a single fragment" do fragments = BigBench::Fragment.parse(@benchmark){ get "/" } fragments.size.should == 1 fragments.first.uri.to_s.should == "http://localhost:3001/" end it "should parse multiple fragments" do fragments = BigBench::Fragment.parse(@benchmark) do get "/index" get "/page" end fragments.size.should == 2 fragments.first.uri.to_s.should == "http://localhost:3001/index" fragments.last.uri.to_s.should == "http://localhost:3001/page" end context "should support following fragment methods" do it "GET" do fragments = BigBench::Fragment.parse(@benchmark){ get "/" } fragments.size.should == 1 fragments.first.uri.to_s.should == "http://localhost:3001/" fragments.first.method.should == :get fragments.first.params.should == {} end it "POST" do fragments = BigBench::Fragment.parse(@benchmark){ post "/login", { :user => "tommy@test.com", :password => "secret" } } fragments.size.should == 1 fragments.first.uri.to_s.should == "http://localhost:3001/login" fragments.first.method.should == :post fragments.first.params.should == { :user => "tommy@test.com", :password => "secret" } end it "PUT" do fragments = BigBench::Fragment.parse(@benchmark){ put "/books", { :book => "A Book" } } fragments.size.should == 1 fragments.first.uri.to_s.should == "http://localhost:3001/books" fragments.first.method.should == :put fragments.first.params.should == { :book => "A Book" } end it "DELETE" do fragments = BigBench::Fragment.parse(@benchmark){ delete "/books/5", { :user => "tommy@test.com", :password => "secret" } } fragments.size.should == 1 fragments.first.uri.to_s.should == "http://localhost:3001/books/5" fragments.first.method.should == :delete fragments.first.params.should == { :user => "tommy@test.com", :password => "secret" } end end context "should run following fragment methods" do it "GET" do fragment = BigBench::Fragment.parse(@benchmark){ get "/" }.first result = nil Net::HTTP.start(fragment.uri.host, fragment.uri.port) do |http| result = fragment.run!(http) end result.code.to_i.should == 200 result.body.should == "Test" @benchmark.tracker.trackings.size.should == 1 end it "POST" do fragment = BigBench::Fragment.parse(@benchmark){ post "/" }.first result = nil Net::HTTP.start(fragment.uri.host, fragment.uri.port) do |http| result = fragment.run!(http) end result.code.to_i.should == 200 result.body.should == "Test" @benchmark.tracker.trackings.size.should == 1 end it "PUT" do fragment = BigBench::Fragment.parse(@benchmark){ put "/" }.first result = nil Net::HTTP.start(fragment.uri.host, fragment.uri.port) do |http| result = fragment.run!(http) end result.code.to_i.should == 200 result.body.should == "Test" @benchmark.tracker.trackings.size.should == 1 end it "DELETE" do fragment = BigBench::Fragment.parse(@benchmark){ delete "/" }.first result = nil Net::HTTP.start(fragment.uri.host, fragment.uri.port) do |http| result = fragment.run!(http) end result.code.to_i.should == 200 result.body.should == "Test" @benchmark.tracker.trackings.size.should == 1 end end end