 b70165c3b4
			
		
	
	
		b70165c3b4
		
	
	
	
	
		
			
			fixed role name new field validators without validate fields types fixed error with user parser todo: project tests returned some tests, users fixed some more tests: filters images tests network tests keys tests test generator fixed run_list validator
		
			
				
	
	
		
			54 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require 'json'
 | |
| require 'pp'
 | |
| 
 | |
| class FixtureFormatter
 | |
| 
 | |
|   def initialize(fixtures)
 | |
|     @fixtures = fixtures
 | |
|     if ENV["DEBUG"]
 | |
|       puts "Loaded fixtures:"
 | |
|       pp @fixtures
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def json(path, options={})
 | |
|     result = nil
 | |
|     begin
 | |
|       result = JSON.pretty_generate(get_fixture(path, options))
 | |
|     rescue
 | |
|       raise "Fixture '#{path}' is absent"
 | |
|     end
 | |
|     options[:spaces] = 4 unless options[:spaces]
 | |
|     result = shift_to_right(result, options[:spaces])
 | |
|     result
 | |
|   end
 | |
| 
 | |
|   def get_fixture(path, options={})
 | |
|     keys = path.split('/')
 | |
|     hash = @fixtures
 | |
|     keys.each do |key|
 | |
|       hash = hash[key]
 | |
|     end
 | |
|     hash = hash.clone
 | |
|     hash.merge!(options[:value]) if options[:value]
 | |
|     hash.delete(options[:without_field]) if options[:without_field]
 | |
|     hash
 | |
|   end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def shift_to_right(text, spaces_count)
 | |
|     buffer = ''
 | |
|     first_line = true
 | |
|     text.each_line do |line|
 | |
|       if first_line
 | |
|         first_line = false
 | |
|         buffer += line
 | |
|         next
 | |
|       end
 | |
|       buffer += (' ' * spaces_count) + line
 | |
|     end
 | |
|     buffer
 | |
|   end
 | |
| end
 |