made access to the library a bit better
[ruby-calais.git] / spec / calais_spec.rb
blob9077f1ab49caf4fa4cbf8f0297cd4b3e71356477
1 require File.expand_path("#{File.dirname(__FILE__)}/helper")
3 describe Calais do
4   it "provides a version number" do
5     Calais::VERSION.should_not be_nil
6   end
7 end
9 describe Calais, ".new" do
10   it "accepts arguments as a hash" do
11     client = nil
12     
13     lambda { client = Calais.new(:content => SAMPLE_DOCUMENT) }.should_not raise_error(ArgumentError)
15     client.license_id.should == LICENSE_KEY
16     client.content.should == SAMPLE_DOCUMENT
17   end
18   
19   it "accepts arguments as a block" do
20     client = nil
21     
22     lambda {
23       client = Calais.new do |c|
24         c.content = SAMPLE_DOCUMENT
25       end
26     }.should_not raise_error(ArgumentError)
28     client.license_id.should == LICENSE_KEY
29     client.content.should == SAMPLE_DOCUMENT
30   end
31   
32   it "should not accept unkonwn attributes" do
33     lambda { Calais.new(:monkey => "monkey") }.should raise_error(NoMethodError)
34   end
35 end
37 describe Calais, ".enlighten" do
38   before(:all) do
39     @marked = Calais.enlighten(:content => SAMPLE_DOCUMENT, :content_type => :xml)
40   end
41   
42   it "returns a string" do
43     @marked.should_not be_nil
44     @marked.should be_a_kind_of(String)
45   end
46 end
48 describe Calais, ".call" do
49   before(:all) do
50     @client = Calais.new(:content => SAMPLE_DOCUMENT)
51   end
53   it "accepts known methods" do
54     lambda { @client.call('enlighten') }.should_not raise_error(ArgumentError)
55   end
57   it "complains about unkown methods" do
58     lambda { @client.call('monkey') }.should raise_error(ArgumentError)
59   end
60 end
62 describe Calais, ".params_xml" do
63   it "returns an xml encoded string" do
64     client = Calais.new(:content => SAMPLE_DOCUMENT, :content_type => :xml)
65     client.send("params_xml").should_not be_nil
66     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>]
67   end
68 end