class Fixture
Attributes
file[R]
locals[R]
Public Class Methods
new(file, locals = {})
click to toggle source
# File spec/support/fixtures.rb, line 10 def initialize(file, locals = {}) @file = fixture(file) @locals = locals end
Public Instance Methods
fixture(file)
click to toggle source
# File spec/support/fixtures.rb, line 19 def fixture(file) File.new(File.join(fixture_path, "/", file)) end
fixture_path()
click to toggle source
# File spec/support/fixtures.rb, line 15 def fixture_path File.expand_path("../../fixtures", __FILE__) end
to_json()
click to toggle source
# File spec/support/fixtures.rb, line 31 def to_json if File.extname(file) == ".erb" rendered_file = ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding }) JSON.parse(rendered_file) else JSON.parse(template_file_content) end end
to_json_hashie()
click to toggle source
# File spec/support/fixtures.rb, line 40 def to_json_hashie json = self.to_json if json.is_a? Array json.map {|json_object| Hashie::Mash.new json_object } else Hashie::Mash.new json end end
to_s()
click to toggle source
# File spec/support/fixtures.rb, line 23 def to_s if File.extname(file) == ".erb" ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding }).to_s else template_file_content.to_s end end
Private Instance Methods
template_file_content()
click to toggle source
# File spec/support/fixtures.rb, line 51 def template_file_content @file_content ||= file.read end