Skip to content

Commit

Permalink
fix build in jruby
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Jan 1, 2023
1 parent a94e412 commit d117199
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ group :test do
gem "multi_json", require: false
gem "nokogiri", require: false
end
gem 'pry-byebug'
gem 'pry-byebug', platform: :mri

52 changes: 34 additions & 18 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
require 'pry-byebug'
# frozen_string_literal: true

begin
require 'pry-byebug'
rescue LoadError
end

require 'representable'

require 'minitest/autorun'
require 'test_xml/mini_test'

require "representable/debug"
require 'representable/debug'
require 'minitest/assertions'

module MiniTest::Assertions
def assert_equal_xml(text, subject)
assert_equal (text.gsub("\n", "").gsub(/(\s\s+)/, "")), subject.gsub("\n", "").gsub(/(\s\s+)/, "")
module MiniTest
module Assertions
def assert_equal_xml(text, subject)
assert_equal text.gsub("\n", '').gsub(/(\s\s+)/, ''), subject.gsub("\n", '').gsub(/(\s\s+)/, '')
end
end
end
String.infect_an_assertion :assert_equal_xml, :must_xml

# TODO: delete all that in 4.0:
class Album
attr_accessor :songs, :best_song
def initialize(songs=nil, best_song=nil)

def initialize(songs = nil, best_song = nil)
@songs = songs
@best_song = best_song
end
Expand All @@ -29,7 +38,8 @@ def ==(other)

class Song
attr_accessor :name, :track # never change this, track rendered with Rails#to_json.
def initialize(name=nil, track=nil)

def initialize(name = nil, track = nil)
@name = name
@track = track
end
Expand All @@ -47,9 +57,9 @@ def xml(document)

module AssertJson
module Assertions
def assert_json(expected, actual, msg=nil)
msg = message(msg, "") { diff expected, actual }
assert_equal(expected.split("").sort, actual.split("").sort, msg)
def assert_json(expected, actual, msg = nil)
msg = message(msg, '') { diff expected, actual }
assert_equal(expected.split('').sort, actual.split('').sort, msg)
end
end
end
Expand Down Expand Up @@ -77,16 +87,18 @@ class AssertableDocument
attr_reader :document

def initialize(document, format)
@document, @format = document, format
@document = document
@format = format
end

def must_equal_document(*args)
return document.must_equal_xml(*args) if @format == :xml

document.must_equal(*args)
end
end

def self.representer!(options={}, &block)
def self.representer!(options = {}, &block)
fmt = options # we need that so the 2nd call to ::let(within a ::describe) remembers the right format.

name = options[:name] || :representer
Expand Down Expand Up @@ -119,25 +131,29 @@ def inject_representer(mod, options)
end

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

alias_method :representer!, :representer_for
alias representer! representer_for
end
include TestMethods
end

class BaseTest < MiniTest::Spec
let(:new_album) { OpenStruct.new.extend(representer) }
let(:album) { OpenStruct.new(:songs => ["Fuck Armageddon"]).extend(representer) }
let(:song) { OpenStruct.new(:title => "Resist Stance") }
let(:song_representer) { Module.new do include Representable::Hash; property :title end }

let(:album) { OpenStruct.new(songs: ['Fuck Armageddon']).extend(representer) }
let(:song) { OpenStruct.new(title: 'Resist Stance') }
let(:song_representer) do
Module.new do
include Representable::Hash
property :title
end
end
end

Band = Struct.new(:id, :name) do
Expand Down

0 comments on commit d117199

Please sign in to comment.