11# frozen_string_literal: true
22
3- require ' test_helper'
3+ require " test_helper"
44
55class 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
3327end
@@ -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