Sha256: 21b5af8990fd4bb83d89a1443b0ea67fb54aaa9e1f19ea1a7c61ff8d5430bf59
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
require 'spec_helper' require 'commute/core/api' describe Commute::Api do class TestApi < Commute::Api with(text: 'hello world') with(id: 1) using do sequence.append Proc.new {} end def all with(text: 'go', help: true).get end end class TestInheritance < TestApi with(id: 2) using do sequence.append Proc.new {} end end let(:api_klass) { TestApi } let(:api_klass2) do Class.new(Commute::Api) do with text: 'goodbye world' end end it 'should allow us to define a base context' do api_klass.context.parameters.must_equal id: 1, text: 'hello world' end it 'should isolate base contexts for each api' do api_klass2.context.parameters.must_equal text: 'goodbye world' end it 'should allow us to modify the base context externally' do build = api_klass.builder.with id: 2 api_klass.context.parameters[:id].must_equal 2 api_klass.builder.with id: 1 end it 'should create a new Api instance when a method is called on the class' do api_klass.builder[:id].must_equal 1 context = api_klass.with(id: 2).all.context context.parameters.must_equal id: 2, text: 'go', help: true api_klass.builder[:id].must_equal 1 end it 'should deal with inheritance' do context = TestInheritance.new.context context.parameters[:id].must_equal 2 context.stack.sequence.size.must_be :>=, 2 end describe '#new' do it 'should build on the base context without modifying it' do api = api_klass.new.context api.with(id: 2).parameters[:id].must_equal 2 context = api.with(text: 'hi!').all.context context.parameters[:id].must_equal 1 context.with(id: 2).parameters.must_equal text: 'go', help: true, id: 2 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
commute-0.3.0.pre.2 | spec/commute/core/api_spec.rb |
commute-0.3.0.pre | spec/commute/core/api_spec.rb |