Sha256: f0bc97ef0ea7f46fbd682de0b0cd8f290415b43c8cc19d3c5c9beeb864ebfac3

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'representable'
require 'representable/json'
require 'representable/xml'
require 'test/unit'
require 'minitest/spec'
require 'minitest/autorun'
require 'test_xml/mini_test'
require 'mocha/setup'

class Album
  attr_accessor :songs, :best_song
  def initialize(songs=nil, best_song=nil)
    @songs      = songs
    @best_song  = best_song
  end

  def ==(other)
    songs == other.songs and best_song == other.best_song
  end
end

class Song
  attr_accessor :name, :track
  def initialize(name=nil, track=nil)
    @name   = name
    @track  = track
  end

  def ==(other)
    name == other.name and track == other.track
  end
end

module XmlHelper
  def xml(document)
    Nokogiri::XML(document).root
  end
end

module AssertJson
  module Assertions
    def assert_json(expected, actual, msg=nil)
      msg = message(msg, "") { diff expected, actual }
      assert(expected.split("").sort == actual.split("").sort, msg)
    end
  end
end

MiniTest::Spec.class_eval do
  include AssertJson::Assertions
  include XmlHelper

  def self.representer!(format=Representable::Hash, name=:representer, &block)
    let(name) do
      Module.new do
        include format
        instance_exec(&block)
      end
    end
  end

  module TestMethods
    def representer_for(modules=[Representable::Hash], &block)
      Module.new do
        extend TestMethods
        include *modules
        module_exec(&block)
      end
    end
  end
  include TestMethods
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
representable-1.5.0 test/test_helper.rb
representable-1.4.2 test/test_helper.rb
representable-1.4.1 test/test_helper.rb
representable-1.4.0 test/test_helper.rb
representable-1.3.5 test/test_helper.rb
representable-1.3.4 test/test_helper.rb
representable-1.3.3 test/test_helper.rb