Skip to content

Commit 8a3dd0b

Browse files
committed
use 2.7 format
1 parent f40d0b0 commit 8a3dd0b

58 files changed

Lines changed: 1622 additions & 1491 deletions

Some content is hidden

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

test/as_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# frozen_string_literal: true
22

3-
require 'test_helper'
3+
require "test_helper"
44

55
class AsTest < MiniTest::Spec
66
for_formats(
7-
hash: [Representable::Hash, { 'title' => 'Wie Es Geht' }, { 'title' => 'Revolution' }]
7+
hash: [Representable::Hash, {"title" => "Wie Es Geht"}, {"title" => "Revolution"}]
88
# :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>"],
99
# :yaml => [Representable::YAML, "---\nsong:\n name: Alive\n", "---\nsong:\n name: You've Taken Everything\n"],
1010
) do |format, mod, input, output|
11-
let(:song) { representer.prepare(Song.new('Revolution')) }
11+
let(:song) { representer.prepare(Song.new("Revolution")) }
1212
let(:format) { format }
1313

14-
describe 'as: with :symbol' do
14+
describe "as: with :symbol" do
1515
representer!(module: mod) do
1616
property :name, as: :title
1717
end
1818

1919
it { assert_equal_document render(song), output }
20-
it { _(parse(song, input).name).must_equal 'Wie Es Geht' }
20+
it { _(parse(song, input).name).must_equal "Wie Es Geht" }
2121
end
2222

23-
describe 'as: with lambda' do
23+
describe "as: with lambda" do
2424
representer!(module: mod) do
2525
property :name, as: ->(*) { self.class.to_s }
2626
end
2727

28-
it { assert_equal_document(render(song), { 'Song' => 'Revolution' }) }
29-
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" }
3030
end
3131

32-
describe 'lambda arguments' do
32+
describe "lambda arguments" do
3333
representer! do
3434
property :name, as: ->(options) { options[:user_options].inspect }
3535
end
3636

37-
it { assert_equal_document(render(song, user_options: { volume: 1 }), { '{:volume=>1}' => 'Revolution' }) }
37+
it { assert_equal_document(render(song, user_options: {volume: 1}), {"{:volume=>1}" => "Revolution"}) }
3838
it {
39-
_(parse(song, { '{:volume=>1}' => 'Wie Es Geht' }, user_options: { volume: 1 }).name).must_equal 'Wie Es Geht'
39+
_(parse(song, {"{:volume=>1}" => "Wie Es Geht"}, user_options: {volume: 1}).name).must_equal "Wie Es Geht"
4040
}
4141
end
4242
end
@@ -62,6 +62,6 @@ class AsXmlTest < MiniTest::Spec
6262
<combo>
6363
<name>Offspring</name>
6464
</combo>
65-
</album>", representer.new(Album.new(Band.new('Offspring'))).to_xml
65+
</album>", representer.new(Album.new(Band.new("Offspring"))).to_xml
6666
end
6767
end

test/benchmarking.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

3-
require 'test_helper'
4-
require 'benchmark'
3+
require "test_helper"
4+
require "benchmark"
55

6-
SONG_PROPERTIES = 1000.times.collect do |i|
6+
SONG_PROPERTIES = Array.new(1000) do |i|
77
"property_#{i}"
88
end
99

@@ -27,22 +27,22 @@ module AlbumRepresenter
2727
end
2828

2929
def random_song
30-
attrs = Hash[SONG_PROPERTIES.collect { |n| [n, n] }]
30+
attrs = SONG_PROPERTIES.to_h { |n| [n, n] }
3131
OpenStruct.new(attrs)
3232
end
3333

3434
times = []
3535

3636
3.times.each do
37-
album = OpenStruct.new(songs: 100.times.collect { random_song })
37+
album = OpenStruct.new(songs: Array.new(100) { random_song })
3838

3939
times << Benchmark.measure do
40-
puts '================ next!'
40+
puts "================ next!"
4141
album.extend(AlbumRepresenter).to_json
4242
end
4343
end
4444

45-
puts times.join('')
45+
puts times.join
4646

4747
# 100 songs, 100 attrs
4848
# 0.050000 0.000000 0.050000 ( 0.093157)

test/binding_test.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# frozen_string_literal: true
22

3-
require 'test_helper'
3+
require "test_helper"
44

55
class BindingTest < MiniTest::Spec
66
Binding = Representable::Binding
77
let(:render_nil_definition) { Representable::Definition.new(:song, render_nil: true) }
88

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

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

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

2121
# don't skip when nil and :render_nil undefined.
22-
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 }
2323
end
2424

25-
describe '#default_for' do
26-
let(:definition) { Representable::Definition.new(:song, default: 'Insider') }
25+
describe "#default_for" do
26+
let(:definition) { Representable::Definition.new(:song, default: "Insider") }
2727
let(:binding) { Binding.new(definition) }
2828

2929
# return value when value present.
30-
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" }
3131

3232
# return false when value false.
3333
it { _(binding.default_for(false)).must_equal false }
3434

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

3838
# return nil when value nil and render_nil: true.
3939
it { _(Binding.new(render_nil_definition).default_for(nil)).must_be_nil }
@@ -44,7 +44,7 @@ class BindingTest < MiniTest::Spec
4444
Binding.new(
4545
Representable::Definition.new(
4646
:song, render_nil: true,
47-
default: 'The Quest'
47+
default: "The Quest"
4848
)
4949
).default_for(nil)
5050
).must_be_nil

test/cached_test.rb

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# frozen_string_literal: true
22

3-
require 'test_helper'
3+
require "test_helper"
44

55
class Profiler
66
def self.profile(&block)
77
case RUBY_ENGINE
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
25-
when 'truffleruby'
26-
require 'truffleruby-tool'
27-
28-
output = StringIO.new
29-
TruffleRubyTool.profile(&block)
30-
output.string
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
3125
end
3226
end
3327
end
@@ -59,29 +53,29 @@ class AlbumRepresenter < Representable::Decorator
5953
collection :songs, decorator: SongRepresenter, class: Model::Song
6054
end
6155

62-
describe 'serialization' do
56+
describe "serialization" do
6357
let(:album_hash) do
6458
{
65-
'name' => 'Louder And Even More Dangerous',
66-
'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}"}]
6761
}
6862
end
6963

70-
let(:song) { Model::Song.new('Jailbreak') }
71-
let(:song2) { Model::Song.new('Southbound') }
72-
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")]) }
7367
let(:representer) { AlbumRepresenter.new(album) }
7468

7569
it do
7670
# album2 = Model::Album.new("Louder And Even More Dangerous", [song2, song])
7771

7872
# makes sure options are passed correctly.
79-
_(representer.to_hash(user_options: { volume: 9 })).must_equal(
73+
_(representer.to_hash(user_options: {volume: 9})).must_equal(
8074
{
81-
'name' => 'Live And Dangerous',
82-
'songs' => [
83-
{ 'title' => 'Jailbreak:{:volume=>9}' }, { 'title' => 'Southbound:{:volume=>9}' },
84-
{ '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}"}
8579
]
8680
}
8781
) # called in Deserializer/Serializer
@@ -95,6 +89,7 @@ class AlbumRepresenter < Representable::Decorator
9589

9690
# profiling
9791
it do
92+
skip("TruffleRuby profiler is not implemented yet") if RUBY_ENGINE == "truffleruby"
9893
representer.to_hash
9994

10095
data = Profiler.profile { representer.to_hash }
@@ -109,24 +104,24 @@ class AlbumRepresenter < Representable::Decorator
109104
# 3 nested decorator is instantiated for 3 Songs, though.
110105
_(data).must_match(/3\s*(<Class::)?Representable::Decorator>?[\#.]prepare/m)
111106
# no Binding is instantiated at runtime.
112-
_(data).wont_match 'Representable::Binding#initialize'
107+
_(data).wont_match "Representable::Binding#initialize"
113108
# 2 mappers for Album, Song
114109
# data.must_match "2 Representable::Mapper::Methods#initialize"
115110
# title, songs, 3x title, composer
116111
_(data).must_match(/8\s*Representable::Binding[#.]render_pipeline/m)
117-
_(data).wont_match 'render_functions'
118-
_(data).wont_match 'Representable::Binding::Factories#render_functions'
112+
_(data).wont_match "render_functions"
113+
_(data).wont_match "Representable::Binding::Factories#render_functions"
119114
end
120115
end
121116

122-
describe 'deserialization' do
117+
describe "deserialization" do
123118
let(:album_hash) do
124119
{
125-
'name' => 'Louder And Even More Dangerous',
126-
'songs' => [
127-
{ 'title' => 'Southbound', 'composer' => { 'name' => 'Lynott' } },
128-
{ 'title' => 'Jailbreak', 'composer' => { 'name' => 'Phil Lynott' } },
129-
{ 'title' => 'Emerald' }
120+
"name" => "Louder And Even More Dangerous",
121+
"songs" => [
122+
{"title" => "Southbound", "composer" => {"name" => "Lynott"}},
123+
{"title" => "Jailbreak", "composer" => {"name" => "Phil Lynott"}},
124+
{"title" => "Emerald"}
130125
]
131126
}
132127
end
@@ -137,18 +132,19 @@ class AlbumRepresenter < Representable::Decorator
137132
AlbumRepresenter.new(album).from_hash(album_hash)
138133

139134
_(album.songs.size).must_equal 3
140-
_(album.name).must_equal 'Louder And Even More Dangerous'
141-
_(album.songs[0].title).must_equal 'Southbound'
142-
_(album.songs[0].composer.name).must_equal 'Lynott'
143-
_(album.songs[1].title).must_equal 'Jailbreak'
144-
_(album.songs[1].composer.name).must_equal 'Phil Lynott'
145-
_(album.songs[2].title).must_equal 'Emerald'
135+
_(album.name).must_equal "Louder And Even More Dangerous"
136+
_(album.songs[0].title).must_equal "Southbound"
137+
_(album.songs[0].composer.name).must_equal "Lynott"
138+
_(album.songs[1].title).must_equal "Jailbreak"
139+
_(album.songs[1].composer.name).must_equal "Phil Lynott"
140+
_(album.songs[2].title).must_equal "Emerald"
146141
_(album.songs[2].composer).must_be_nil
147142

148143
# TODO: test options.
149144
end
150145

151-
it 'xxx' do
146+
it "xxx" do
147+
skip("TruffleRuby profiler is not implemented yet") if RUBY_ENGINE == "truffleruby"
152148
representer = AlbumRepresenter.new(Model::Album.new)
153149
representer.from_hash(album_hash)
154150

@@ -159,9 +155,9 @@ class AlbumRepresenter < Representable::Decorator
159155
# MRI and JRuby has different output formats. See note above.
160156
_(data).must_match(/5\s*(<Class::)?Representable::Decorator>?[#.]prepare/)
161157
# a total of 5 properties in the object graph.
162-
_(data).wont_match 'Representable::Binding#initialize'
158+
_(data).wont_match "Representable::Binding#initialize"
163159

164-
_(data).wont_match 'parse_functions' # no pipeline creation.
160+
_(data).wont_match "parse_functions" # no pipeline creation.
165161
_(data).must_match(/10\s*Representable::Binding[#.]parse_pipeline/)
166162
# three mappers for Album, Song, composer
167163
# data.must_match "3 Representable::Mapper::Methods#initialize"

0 commit comments

Comments
 (0)