1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
3
5
class Profiler
4
6
def self . profile ( &block )
5
7
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
23
25
end
24
26
end
25
27
end
@@ -51,29 +53,29 @@ class AlbumRepresenter < Representable::Decorator
51
53
collection :songs , decorator : SongRepresenter , class : Model ::Song
52
54
end
53
55
54
- describe " serialization" do
56
+ describe ' serialization' do
55
57
let ( :album_hash ) do
56
58
{
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}' } ]
59
61
}
60
62
end
61
63
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' ) ] ) }
65
67
let ( :representer ) { AlbumRepresenter . new ( album ) }
66
68
67
69
it do
68
70
# album2 = Model::Album.new("Louder And Even More Dangerous", [song2, song])
69
71
70
72
# 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 (
72
74
{
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}' }
77
79
]
78
80
}
79
81
) # called in Deserializer/Serializer
@@ -101,24 +103,24 @@ class AlbumRepresenter < Representable::Decorator
101
103
# 3 nested decorator is instantiated for 3 Songs, though.
102
104
_ ( data ) . must_match ( /3\s *(<Class::)?Representable::Decorator>?[\# .]prepare/m )
103
105
# no Binding is instantiated at runtime.
104
- _ ( data ) . wont_match " Representable::Binding#initialize"
106
+ _ ( data ) . wont_match ' Representable::Binding#initialize'
105
107
# 2 mappers for Album, Song
106
108
# data.must_match "2 Representable::Mapper::Methods#initialize"
107
109
# title, songs, 3x title, composer
108
110
_ ( 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'
111
113
end
112
114
end
113
115
114
- describe " deserialization" do
116
+ describe ' deserialization' do
115
117
let ( :album_hash ) do
116
118
{
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' }
122
124
]
123
125
}
124
126
end
@@ -129,18 +131,18 @@ class AlbumRepresenter < Representable::Decorator
129
131
AlbumRepresenter . new ( album ) . from_hash ( album_hash )
130
132
131
133
_ ( 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'
138
140
_ ( album . songs [ 2 ] . composer ) . must_be_nil
139
141
140
142
# TODO: test options.
141
143
end
142
144
143
- it " xxx" do
145
+ it ' xxx' do
144
146
representer = AlbumRepresenter . new ( Model ::Album . new )
145
147
representer . from_hash ( album_hash )
146
148
@@ -151,9 +153,9 @@ class AlbumRepresenter < Representable::Decorator
151
153
# MRI and JRuby has different output formats. See note above.
152
154
_ ( data ) . must_match ( /5\s *(<Class::)?Representable::Decorator>?[#.]prepare/ )
153
155
# a total of 5 properties in the object graph.
154
- _ ( data ) . wont_match " Representable::Binding#initialize"
156
+ _ ( data ) . wont_match ' Representable::Binding#initialize'
155
157
156
- _ ( data ) . wont_match " parse_functions" # no pipeline creation.
158
+ _ ( data ) . wont_match ' parse_functions' # no pipeline creation.
157
159
_ ( data ) . must_match ( /10\s *Representable::Binding[#.]parse_pipeline/ )
158
160
# three mappers for Album, Song, composer
159
161
# data.must_match "3 Representable::Mapper::Methods#initialize"
0 commit comments