1 require File.expand_path("#{File.dirname(__FILE__)}/helper")
4 it "provides a version number" do
5 Calais::VERSION.should_not be_nil
9 describe Calais::Client, ".new" do
10 it "accepts arguments as a hash" do
13 lambda { client = Calais::Client.new(:content => SAMPLE_DOCUMENT, :license_id => LICENSE_ID) }.should_not raise_error(ArgumentError)
15 client.license_id.should == LICENSE_ID
16 client.content.should == SAMPLE_DOCUMENT
19 it "accepts arguments as a block" do
23 client = Calais::Client.new do |c|
24 c.content = SAMPLE_DOCUMENT
25 c.license_id = LICENSE_ID
27 }.should_not raise_error(ArgumentError)
29 client.license_id.should == LICENSE_ID
30 client.content.should == SAMPLE_DOCUMENT
33 it "should not accept unknown attributes" do
34 lambda { Calais::Client.new(:monkey => "monkey", :license_id => LICENSE_ID) }.should raise_error(NoMethodError)
38 describe Calais, ".process_document" do
39 it "returns a Calais::Response" do
40 response = Calais.process_document(:content => SAMPLE_DOCUMENT, :content_type => :xml, :license_id => LICENSE_ID)
41 response.should_not be_nil
42 response.should be_a_kind_of(Calais::Response)
45 it "returns a Calais::Response (with relationships)" do
46 response = Calais.process_document(:content => File.read(File.join(File.dirname(__FILE__), 'fixtures', 'bicycles_austrailia.xml')), :content_type => :xml, :license_id => LICENSE_ID)
47 response.should_not be_nil
48 response.should be_a_kind_of(Calais::Response)
52 describe Calais::Client, ".call" do
54 @client = Calais::Client.new(:content => SAMPLE_DOCUMENT, :license_id => LICENSE_ID)
57 it "accepts known methods" do
58 lambda { @client.call('enlighten') }.should_not raise_error(ArgumentError)
61 it "complains about unkown methods" do
62 lambda { @client.call('monkey') }.should raise_error(ArgumentError)
66 describe Calais::Client, ".params_xml" do
67 it "returns an xml encoded string" do
68 client = Calais::Client.new(:content => SAMPLE_DOCUMENT, :content_type => :xml, :license_id => LICENSE_ID)
69 client.send("params_xml").should_not be_nil
70 client.send("params_xml").should == %[<c:params xmlns:c=\"http://s.opencalais.com/1/pred/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"><c:processingDirectives c:contentType=\"TEXT/XML\" c:outputFormat=\"XML/RDF\"></c:processingDirectives><c:userDirectives c:allowDistribution=\"false\" c:allowSearch=\"false\" c:externalID=\"dc68d5a382724c2238d9f22ba9c0b4d2581569d8\" c:submitter=\"calais.rb\"></c:userDirectives><c:externalMetadata></c:externalMetadata></c:params>]