Sha256: 004c1e2887f9cd65c2486b5461f04e63b355c32c7e58a34b5a55e9b455b68150

Contents?: true

Size: 1.78 KB

Versions: 11

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'

describe Wordnik::OperationParameter do

  before(:each) do
    @operation_parameter = Wordnik::OperationParameter.new(JSON.parse(sample_resource_body)['apis'].first['operations'].first['parameters'].first)
  end

  it "initializes" do
    @operation_parameter.should respond_to(:name)
    @operation_parameter.should respond_to(:description)
    @operation_parameter.should respond_to(:required)
    @operation_parameter.should respond_to(:param_type)
    @operation_parameter.should respond_to(:default_value)
    @operation_parameter.should respond_to(:allowable_values)
    @operation_parameter.should respond_to(:param_access)
  end    

  context "human_name" do
    it "is inferred from name" do
      @operation_parameter.should_receive(:param_type).and_return('path')
      @operation_parameter.human_name.should == @operation_parameter.name
    end
  
    it "is made more descriptive when it's the actual body of the request" do
      @operation_parameter.should_receive(:param_type).and_return('body')
      @operation_parameter.human_name.should == 'request body'
    end
  end
  
  it "is required if it's a path param" do
    @operation_parameter.should_receive(:required).and_return(false)
    @operation_parameter.should_receive(:param_type).and_return('path')
    @operation_parameter.required?.should == true
  end

  it "is positional if it's a body param" do
    @operation_parameter.should_receive(:param_type).and_return('body')
    @operation_parameter.positional?.should == true
  end

  it "is positional if it's a path param (except for 'format')" do
    @operation_parameter.should_receive(:param_type).at_least(:once).and_return('path')
    @operation_parameter.should_receive(:name).and_return('coolness')
    @operation_parameter.positional?.should == true
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wordnik-4.12 spec/operation_parameter_spec.rb
wordnik-4.11 spec/operation_parameter_spec.rb
wordnik-4.10 spec/operation_parameter_spec.rb
wordnik-4.09 spec/operation_parameter_spec.rb
wordnik-4.08 spec/operation_parameter_spec.rb
wordnik-4.07 spec/operation_parameter_spec.rb
wordnik-4.06.15 spec/operation_parameter_spec.rb
wordnik-4.06.14 spec/operation_parameter_spec.rb
wordnik-4.06.13 spec/operation_parameter_spec.rb
wordnik-4.06.12 spec/operation_parameter_spec.rb
wordnik-4.06.11 spec/operation_parameter_spec.rb