Sha256: b3100988a3f8e88fe4c50cb954cdcfd293133dc5a1f9286eb654f26a93c85aa4

Contents?: true

Size: 939 Bytes

Versions: 9

Compression:

Stored size: 939 Bytes

Contents

require 'spec_helper'

# For some reason, I can't use let or subject when I'm doing this class new extend 
# thing and call methods from it, so instead I'm just calling it manually

describe Sinatra::APIResponse do
  context "#api_response" do
    it "should have a block given" do
      lambda { Class.new.extend(Sinatra::APIResponse).api_response }.should raise_error('No block given')
    end

    context 'error' do
      it "should respond with the errors" do
        klass = Class.new.extend(Sinatra::APIResponse)
        klass.stubs(:errors).returns([{foo: 'bar'}])
        klass.api_response {{yeah: 'yeahs'}}.should =~ /errors.*foo.*bar/
      end
    end

    context 'no error' do
      it "should respond with what's inside the block" do
        klass = Class.new.extend(Sinatra::APIResponse)
        klass.stubs(:errors).returns([])
        klass.api_response { {foo: 'bar'} }.should =~ /foo.*bar/
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
memcached-manager-0.4.0 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.3.0 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.2.3 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.2.2 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.2.1 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.2.0 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.1.0 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.0.1 spec/lib/extensions/api_response_spec.rb
memcached-manager-0.0.0 spec/lib/extensions/api_response_spec.rb