Class: Poltergeist::ScreenshotOverview::Manager
- Inherits:
-
Object
- Object
- Poltergeist::ScreenshotOverview::Manager
- Includes:
- Singleton
- Defined in:
- lib/poltergeist/screenshot_overview/manager.rb
Instance Method Summary collapse
-
#add_image_from_rspec(argument, example, url_path) ⇒ Object
adds image_path and metadata to our list, returns a full path where the Engine should put the screenshot in.
- #generate_html ⇒ Object
- #groups ⇒ Object
- #start ⇒ Object
Instance Method Details
#add_image_from_rspec(argument, example, url_path) ⇒ Object
adds image_path and metadata to our list, returns a full path where the Engine should put the screenshot in
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/poltergeist/screenshot_overview/manager.rb', line 66 def add_image_from_rspec(argument, example, url_path) blob = caller.find{|i| i[ example.file_path.gsub(/:\d*|^\./,"") ]} file_with_line = blob.split(":")[0,2].join(":") filename = [example.description, argument, file_with_line, SecureRandom.hex(6) ].join(" ").gsub(/\W+/,"_") + ".jpg" full_name = File.join(Poltergeist::ScreenshotOverview.target_directory, filename ) FileUtils.mkdir_p Poltergeist::ScreenshotOverview.target_directory describe = example.[:example_group][:description_args] @files << Screenshot.new({ :url => url_path, :argument => argument, :local_image => filename, :full_path => full_name, :group_description => describe, :example_description => example.description, :file_with_line => file_with_line }) full_name end |
#generate_html ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/poltergeist/screenshot_overview/manager.rb', line 86 def generate_html title = title = "Screenshot Overview (#{Time.now.to_s})" template = ERB.new File.new(Poltergeist::ScreenshotOverview.layout).read, nil, "%" html = template.result(binding) File.open( File.join(Poltergeist::ScreenshotOverview.target_directory, "index.html"), "w+") { |f| f.write html } end |
#groups ⇒ Object
95 96 97 98 99 |
# File 'lib/poltergeist/screenshot_overview/manager.rb', line 95 def groups @files. group_by{ |screenshot| screenshot.test_file}. map{|file,screenshots| ScreenshotGroup.new(file,screenshots.sort_by{|s| s.file_with_line }) } end |
#start ⇒ Object
57 58 59 60 61 62 |
# File 'lib/poltergeist/screenshot_overview/manager.rb', line 57 def start Dir[File.join Poltergeist::ScreenshotOverview.target_directory, "*jpg"].each do |file| File.unlink file end @files = [] end |