Sha256: fe2c3217a465b069183a8a9f4fe8a644b2bfecb3c27d8eecb97e10069b3b6b72

Contents?: true

Size: 1009 Bytes

Versions: 42

Compression:

Stored size: 1009 Bytes

Contents

# encoding: utf-8
require "spec_helper"

describe Her::Middleware::SecondLevelParseJSON do
  subject { described_class.new }

  context "with valid JSON body" do
    let(:body) { "{\"data\": 1, \"errors\": 2, \"metadata\": 3}" }
    it "parses body as json" do
      subject.parse(body).tap do |json|
        json[:data].should == 1
        json[:errors].should == 2
        json[:metadata].should == 3
      end
    end

    it "parses :body key as json in the env hash" do
      env = { :body => body }
      subject.on_complete(env)
      env[:body].tap do |json|
        json[:data].should == 1
        json[:errors].should == 2
        json[:metadata].should == 3
      end
    end
  end

  context "with invalid JSON body" do
    let(:body) { '"foo"' }
    it 'ensures that invalid JSON throws an exception' do
      expect { subject.parse(body) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "\"foo\"")')
    end
  end

end

Version data entries

42 entries across 42 versions & 4 rubygems

Version Path
test_track_rails_client-2.0.0 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-1.3.0 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-1.2.0 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-1.1.0 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-1.0.0 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.20 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.19 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.18 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.17 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.16 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.15 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.14 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.13 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.12 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.11 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.10 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.9 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
test_track_rails_client-0.9.8 vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb
her-0.8.2 spec/middleware/second_level_parse_json_spec.rb
her5-0.8.2 spec/middleware/second_level_parse_json_spec.rb