Sha256: 2a7ee0bce0dede3586dd3ef4a48b6a616b3e4b7d7f4a2588b02c2389ddb58b60

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe Wordnik do

  
  context "instantiation" do

    context "resources" do
      it "instantiates resources from cached JSON" do
        Wordnik.resources.class.should == Hash
        Wordnik.resources[:word].class.should == Wordnik::Resource
      end
      
      it "has as many resources as there are resource names" do
        Wordnik.resources.size.should == Wordnik.resource_names.size
      end

      it "assigns resource keys that match the resource names" do
        Wordnik.resources[:word].name.should == :word
      end
            
    end
    
  end
  
  context "dynamic method_missing magic" do
    
    it "maps shorthand Wordnik.resource calls to their resources" do
      Wordnik.word.class.should == Wordnik::Resource
      Wordnik.word.name.should == :word
    end

    it "builds requests but doesn't run them if method name begins with 'build_'" do
      @request = Wordnik.word.build_get('dynamo')
      @request.class.should == Wordnik::Request
    end

    it "runs requests and returns their body if method name doesn't begin with 'build_'" do
      @response_body = Wordnik.word.get('dynamo')
      @response_body.class.should == Hash
      @response_body.keys.sort.should == %w(canonicalForm word)
    end
    
    context "argument handling" do

      before(:each) do
         @request = Wordnik.word.build_get_examples('dynamo', :skip => 2, :limit => 10)
       end
       
       it "injects required arguments into the path" do
         @request.path.should == "/word/dynamo/examples"
       end

       it "passes optional key-value arguments to the query string" do
         @request.query_string.should == "?limit=10&skip=2"
       end
       
    end
    
    context "wordlists" do
      
      it "creates a wordlist"
      
      it "adds words"
      
      it "updates words"
      
      it "get all the words"
      
      it "deletes a wordlist"
      
    end
        
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wordnik-0.3.2 spec/wordnik_spec.rb
wordnik-0.3.1 spec/wordnik_spec.rb
wordnik-0.3.0 spec/wordnik_spec.rb