Skip to content

Commit 07dc894

Browse files
committed
fix deprecations
1 parent 21d9655 commit 07dc894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2200
-1912
lines changed

test/as_test.rb

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
1-
require "test_helper"
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
24

35
class AsTest < MiniTest::Spec
46
for_formats(
5-
:hash => [Representable::Hash, {"title" => "Wie Es Geht"}, {"title" => "Revolution"}]
7+
hash: [Representable::Hash, { 'title' => 'Wie Es Geht' }, { 'title' => 'Revolution' }]
68
# :xml => [Representable::XML, "<open_struct>\n <song>\n <name>Alive</name>\n </song>\n</open_struct>", "<open_struct><song><name>You've Taken Everything</name></song>/open_struct>"],
79
# :yaml => [Representable::YAML, "---\nsong:\n name: Alive\n", "---\nsong:\n name: You've Taken Everything\n"],
810
) do |format, mod, input, output|
9-
let(:song) { representer.prepare(Song.new("Revolution")) }
11+
let(:song) { representer.prepare(Song.new('Revolution')) }
1012
let(:format) { format }
1113

12-
describe "as: with :symbol" do
13-
representer!(:module => mod) do
14-
property :name, :as => :title
14+
describe 'as: with :symbol' do
15+
representer!(module: mod) do
16+
property :name, as: :title
1517
end
1618

17-
it { render(song).must_equal_document output }
18-
it { _(parse(song, input).name).must_equal "Wie Es Geht" }
19+
it { assert_equal_document render(song), output }
20+
it { _(parse(song, input).name).must_equal 'Wie Es Geht' }
1921
end
2022

21-
describe "as: with lambda" do
22-
representer!(:module => mod) do
23-
property :name, :as => ->(*) { self.class.to_s }
23+
describe 'as: with lambda' do
24+
representer!(module: mod) do
25+
property :name, as: ->(*) { self.class.to_s }
2426
end
2527

26-
it { render(song).must_equal_document({"Song" => "Revolution"}) }
27-
it { _(parse(song, {"Song" => "Wie Es Geht"}).name).must_equal "Wie Es Geht" }
28+
it { assert_equal_document(render(song), { 'Song' => 'Revolution' }) }
29+
it { _(parse(song, { 'Song' => 'Wie Es Geht' }).name).must_equal 'Wie Es Geht' }
2830
end
2931

30-
describe "lambda arguments" do
32+
describe 'lambda arguments' do
3133
representer! do
32-
property :name, :as => ->(options) { options[:user_options].inspect }
34+
property :name, as: ->(options) { options[:user_options].inspect }
3335
end
3436

35-
it { render(song, user_options: {volume: 1}).must_equal_document({"{:volume=>1}" => "Revolution"}) }
36-
it { _(parse(song, {"{:volume=>1}" => "Wie Es Geht"}, user_options: {volume: 1}).name).must_equal "Wie Es Geht" }
37+
it { assert_equal_document(render(song, user_options: { volume: 1 }), { '{:volume=>1}' => 'Revolution' }) }
38+
it {
39+
_(parse(song, { '{:volume=>1}' => 'Wie Es Geht' }, user_options: { volume: 1 }).name).must_equal 'Wie Es Geht'
40+
}
3741
end
3842
end
3943
end
@@ -54,7 +58,10 @@ class AsXmlTest < MiniTest::Spec
5458
end
5559

5660
it do
57-
skip
58-
_(representer.new(Album.new(Band.new("Offspring"))).to_xml).must_equal ""
61+
assert_equal "<album>
62+
<combo>
63+
<name>Offspring</name>
64+
</combo>
65+
</album>", representer.new(Album.new(Band.new('Offspring'))).to_xml
5966
end
6067
end

test/benchmarking.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
require "test_helper"
2-
require "benchmark"
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
4+
require 'benchmark'
35

46
SONG_PROPERTIES = 1000.times.collect do |i|
57
"property_#{i}"
@@ -35,12 +37,12 @@ def random_song
3537
album = OpenStruct.new(songs: 100.times.collect { random_song })
3638

3739
times << Benchmark.measure do
38-
puts "================ next!"
40+
puts '================ next!'
3941
album.extend(AlbumRepresenter).to_json
4042
end
4143
end
4244

43-
puts times.join("")
45+
puts times.join('')
4446

4547
# 100 songs, 100 attrs
4648
# 0.050000 0.000000 0.050000 ( 0.093157)

test/binding_test.rb

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
require "test_helper"
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
24

35
class BindingTest < MiniTest::Spec
46
Binding = Representable::Binding
5-
let(:render_nil_definition) { Representable::Definition.new(:song, :render_nil => true) }
7+
let(:render_nil_definition) { Representable::Definition.new(:song, render_nil: true) }
68

7-
describe "#skipable_empty_value?" do
9+
describe '#skipable_empty_value?' do
810
let(:binding) { Binding.new(render_nil_definition) }
911

1012
# don't skip when present.
11-
it { _(binding.skipable_empty_value?("Disconnect, Disconnect")).must_equal false }
13+
it { _(binding.skipable_empty_value?('Disconnect, Disconnect')).must_equal false }
1214

1315
# don't skip when it's nil and render_nil: true
1416
it { _(binding.skipable_empty_value?(nil)).must_equal false }
@@ -17,21 +19,21 @@ class BindingTest < MiniTest::Spec
1719
it { _(Binding.new(Representable::Definition.new(:song)).skipable_empty_value?(nil)).must_equal true }
1820

1921
# don't skip when nil and :render_nil undefined.
20-
it { _(Binding.new(Representable::Definition.new(:song)).skipable_empty_value?("Fatal Flu")).must_equal false }
22+
it { _(Binding.new(Representable::Definition.new(:song)).skipable_empty_value?('Fatal Flu')).must_equal false }
2123
end
2224

23-
describe "#default_for" do
24-
let(:definition) { Representable::Definition.new(:song, :default => "Insider") }
25+
describe '#default_for' do
26+
let(:definition) { Representable::Definition.new(:song, default: 'Insider') }
2527
let(:binding) { Binding.new(definition) }
2628

2729
# return value when value present.
28-
it { _(binding.default_for("Black And Blue")).must_equal "Black And Blue" }
30+
it { _(binding.default_for('Black And Blue')).must_equal 'Black And Blue' }
2931

3032
# return false when value false.
3133
it { _(binding.default_for(false)).must_equal false }
3234

3335
# return default when value nil.
34-
it { _(binding.default_for(nil)).must_equal "Insider" }
36+
it { _(binding.default_for(nil)).must_equal 'Insider' }
3537

3638
# return nil when value nil and render_nil: true.
3739
it { _(Binding.new(render_nil_definition).default_for(nil)).must_be_nil }
@@ -41,8 +43,8 @@ class BindingTest < MiniTest::Spec
4143
_(
4244
Binding.new(
4345
Representable::Definition.new(
44-
:song, :render_nil => true,
45-
:default => "The Quest"
46+
:song, render_nil: true,
47+
default: 'The Quest'
4648
)
4749
).default_for(nil)
4850
).must_be_nil

test/cached_test.rb

+49-47
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
require "test_helper"
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
24

35
class Profiler
46
def self.profile(&block)
57
case RUBY_ENGINE
6-
when "ruby"
7-
require "ruby-prof"
8-
9-
output = StringIO.new
10-
profile_result = RubyProf.profile(&block)
11-
printer = RubyProf::FlatPrinter.new(profile_result)
12-
printer.print(output)
13-
output.string
14-
when "jruby"
15-
require "jruby/profiler"
16-
17-
output_stream = java.io.ByteArrayOutputStream.new
18-
print_stream = java.io.PrintStream.new(output_stream)
19-
profile_result = JRuby::Profiler.profile(&block)
20-
printer = JRuby::Profiler::FlatProfilePrinter.new(profile_result)
21-
printer.printProfile(print_stream)
22-
output_stream.toString
8+
when 'ruby'
9+
require 'ruby-prof'
10+
11+
output = StringIO.new
12+
profile_result = RubyProf.profile(&block)
13+
printer = RubyProf::FlatPrinter.new(profile_result)
14+
printer.print(output)
15+
output.string
16+
when 'jruby'
17+
require 'jruby/profiler'
18+
19+
output_stream = java.io.ByteArrayOutputStream.new
20+
print_stream = java.io.PrintStream.new(output_stream)
21+
profile_result = JRuby::Profiler.profile(&block)
22+
printer = JRuby::Profiler::FlatProfilePrinter.new(profile_result)
23+
printer.printProfile(print_stream)
24+
output_stream.toString
2325
end
2426
end
2527
end
@@ -51,29 +53,29 @@ class AlbumRepresenter < Representable::Decorator
5153
collection :songs, decorator: SongRepresenter, class: Model::Song
5254
end
5355

54-
describe "serialization" do
56+
describe 'serialization' do
5557
let(:album_hash) do
5658
{
57-
"name" => "Louder And Even More Dangerous",
58-
"songs" => [{"title"=>"Southbound:{:volume=>10}"}, {"title"=>"Jailbreak:{:volume=>10}"}]
59+
'name' => 'Louder And Even More Dangerous',
60+
'songs' => [{ 'title' => 'Southbound:{:volume=>10}' }, { 'title' => 'Jailbreak:{:volume=>10}' }]
5961
}
6062
end
6163

62-
let(:song) { Model::Song.new("Jailbreak") }
63-
let(:song2) { Model::Song.new("Southbound") }
64-
let(:album) { Model::Album.new("Live And Dangerous", [song, song2, Model::Song.new("Emerald")]) }
64+
let(:song) { Model::Song.new('Jailbreak') }
65+
let(:song2) { Model::Song.new('Southbound') }
66+
let(:album) { Model::Album.new('Live And Dangerous', [song, song2, Model::Song.new('Emerald')]) }
6567
let(:representer) { AlbumRepresenter.new(album) }
6668

6769
it do
6870
# album2 = Model::Album.new("Louder And Even More Dangerous", [song2, song])
6971

7072
# makes sure options are passed correctly.
71-
_(representer.to_hash(user_options: {volume: 9})).must_equal(
73+
_(representer.to_hash(user_options: { volume: 9 })).must_equal(
7274
{
73-
"name" => "Live And Dangerous",
74-
"songs" => [
75-
{"title"=>"Jailbreak:{:volume=>9}"}, {"title"=>"Southbound:{:volume=>9}"},
76-
{"title"=>"Emerald:{:volume=>9}"}
75+
'name' => 'Live And Dangerous',
76+
'songs' => [
77+
{ 'title' => 'Jailbreak:{:volume=>9}' }, { 'title' => 'Southbound:{:volume=>9}' },
78+
{ 'title' => 'Emerald:{:volume=>9}' }
7779
]
7880
}
7981
) # called in Deserializer/Serializer
@@ -101,24 +103,24 @@ class AlbumRepresenter < Representable::Decorator
101103
# 3 nested decorator is instantiated for 3 Songs, though.
102104
_(data).must_match(/3\s*(<Class::)?Representable::Decorator>?[\#.]prepare/m)
103105
# no Binding is instantiated at runtime.
104-
_(data).wont_match "Representable::Binding#initialize"
106+
_(data).wont_match 'Representable::Binding#initialize'
105107
# 2 mappers for Album, Song
106108
# data.must_match "2 Representable::Mapper::Methods#initialize"
107109
# title, songs, 3x title, composer
108110
_(data).must_match(/8\s*Representable::Binding[#.]render_pipeline/m)
109-
_(data).wont_match "render_functions"
110-
_(data).wont_match "Representable::Binding::Factories#render_functions"
111+
_(data).wont_match 'render_functions'
112+
_(data).wont_match 'Representable::Binding::Factories#render_functions'
111113
end
112114
end
113115

114-
describe "deserialization" do
116+
describe 'deserialization' do
115117
let(:album_hash) do
116118
{
117-
"name" => "Louder And Even More Dangerous",
118-
"songs" => [
119-
{"title" => "Southbound", "composer" => {"name"=>"Lynott"}},
120-
{"title" => "Jailbreak", "composer" => {"name"=>"Phil Lynott"}},
121-
{"title"=>"Emerald"}
119+
'name' => 'Louder And Even More Dangerous',
120+
'songs' => [
121+
{ 'title' => 'Southbound', 'composer' => { 'name' => 'Lynott' } },
122+
{ 'title' => 'Jailbreak', 'composer' => { 'name' => 'Phil Lynott' } },
123+
{ 'title' => 'Emerald' }
122124
]
123125
}
124126
end
@@ -129,18 +131,18 @@ class AlbumRepresenter < Representable::Decorator
129131
AlbumRepresenter.new(album).from_hash(album_hash)
130132

131133
_(album.songs.size).must_equal 3
132-
_(album.name).must_equal "Louder And Even More Dangerous"
133-
_(album.songs[0].title).must_equal "Southbound"
134-
_(album.songs[0].composer.name).must_equal "Lynott"
135-
_(album.songs[1].title).must_equal "Jailbreak"
136-
_(album.songs[1].composer.name).must_equal "Phil Lynott"
137-
_(album.songs[2].title).must_equal "Emerald"
134+
_(album.name).must_equal 'Louder And Even More Dangerous'
135+
_(album.songs[0].title).must_equal 'Southbound'
136+
_(album.songs[0].composer.name).must_equal 'Lynott'
137+
_(album.songs[1].title).must_equal 'Jailbreak'
138+
_(album.songs[1].composer.name).must_equal 'Phil Lynott'
139+
_(album.songs[2].title).must_equal 'Emerald'
138140
_(album.songs[2].composer).must_be_nil
139141

140142
# TODO: test options.
141143
end
142144

143-
it "xxx" do
145+
it 'xxx' do
144146
representer = AlbumRepresenter.new(Model::Album.new)
145147
representer.from_hash(album_hash)
146148

@@ -151,9 +153,9 @@ class AlbumRepresenter < Representable::Decorator
151153
# MRI and JRuby has different output formats. See note above.
152154
_(data).must_match(/5\s*(<Class::)?Representable::Decorator>?[#.]prepare/)
153155
# a total of 5 properties in the object graph.
154-
_(data).wont_match "Representable::Binding#initialize"
156+
_(data).wont_match 'Representable::Binding#initialize'
155157

156-
_(data).wont_match "parse_functions" # no pipeline creation.
158+
_(data).wont_match 'parse_functions' # no pipeline creation.
157159
_(data).must_match(/10\s*Representable::Binding[#.]parse_pipeline/)
158160
# three mappers for Album, Song, composer
159161
# data.must_match "3 Representable::Mapper::Methods#initialize"

0 commit comments

Comments
 (0)