ENV['RACK_ENV'] = 'test' require 'spec_helper' require 'llt/api' require 'rack/test' def app Api end describe "main api" do include Rack::Test::Methods describe '/segtok' do context "with URI as input" do end let(:text) {{text: "homo mittit. Marcus est."}} context "with text as input" do context "with accept header json" do it "segtoks the given text" do pending get '/segtok', text, {"HTTP_ACCEPT" => "application/json"} last_response.should be_ok response = last_response.body parsed_response = JSON.parse(response) parsed_response.should have(3).items end end context "with accept header xml" do it "segtoks the given text" do pending get '/segtok', text, {"HTTP_ACCEPT" => "application/xml"} last_response.should be_ok body = last_response.body body.should =~ /homo<\/w>/ body.should =~ /mittit<\/w>/ body.should =~ /\.<\/pc>/ end it "receives params for tokenization and markup" do params = { indexing: true, recursive: true, inline: true, }.merge(text) get '/segtok', params, {"HTTP_ACCEPT" => "application/xml"} last_response.should be_ok body = last_response.body body.should =~ /homo<\/w>/ body.should =~ /mittit<\/w>/ body.should =~ /\.<\/pc>/ body.should =~ /Marcus<\/w>/ body.should =~ /est<\/w>/ body.should =~ /\.<\/pc>/ end it "doesn't break with complex embedded xml elements" do txt = { text: 'Arma virumque cano. Troiae qui primus.' } params = { indexing: true, recursive: true, inline: true, xml: true, }.merge(txt) get '/segtok', params, {"HTTP_ACCEPT" => "application/xml"} last_response.should be_ok body = last_response.body elements = [ 'Arma', '', '-que', 'virum', 'cano', '.', 'Troiae', '', 'qui', 'primus', '.' ] body.should =~ /#{elements.join}/ end end end end end