Skip to content

Commit

Permalink
adding fuzz level to the test model. Set at 30 as default, can be ove…
Browse files Browse the repository at this point in the history
…rwritten in post.
  • Loading branch information
fionnbharra committed Mar 9, 2016
1 parent f028d72 commit 4d54667
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/controllers/tests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create

baseline_resize_command = convert_image_command(@test.screenshot_baseline.path, baseline_screenshot_tmp_path, canvas.to_h)
test_size_command = convert_image_command(@test.screenshot.path, test_screenshot_tmp_path, canvas.to_h)
compare_command = compare_images_command(baseline_screenshot_tmp_path, test_screenshot_tmp_path, diff_screenshot_tmp_path, '30%', 'red')
compare_command = compare_images_command(baseline_screenshot_tmp_path, test_screenshot_tmp_path, diff_screenshot_tmp_path, @test.fuzz_level, 'red')

# run all commands in serial
compare_result = Open3.popen3("#{baseline_resize_command} && #{test_size_command} && #{compare_command}") { |_stdin, _stdout, stderr, _wait_thr| stderr.read }
Expand Down Expand Up @@ -109,7 +109,7 @@ def create
private

def test_params
params.require(:test).permit(:name, :platform, :browser, :size, :screenshot, :run_id, :source_url)
params.require(:test).permit(:name, :platform, :browser, :size, :screenshot, :run_id, :source_url, :fuzz_level)
end

def convert_image_command(input_file, output_file, canvas)
Expand Down
1 change: 1 addition & 0 deletions app/models/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ def default_values
self.baseline ||= false
self.dimensions_changed ||= false
self.pass ||= false
self.fuzz_level = '30%' if self.fuzz_level.blank?
end
end
5 changes: 5 additions & 0 deletions db/migrate/20160309104631_add_fuzz_level_to_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFuzzLevelToTests < ActiveRecord::Migration
def change
add_column :tests, :fuzz_level, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160308155000) do
ActiveRecord::Schema.define(version: 20160309104631) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -70,6 +70,7 @@
t.boolean "dimensions_changed"
t.boolean "pass"
t.string "source_url"
t.string "fuzz_level"
end

add_index "tests", ["run_id"], name: "index_tests_on_run_id", using: :btree
Expand Down
3 changes: 1 addition & 2 deletions lib/tasks/screenshots.rake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if Rails.env.development?
screenshot_file = 'about_us.png'
page.save_screenshot(screenshot_file)
puts "Saved screenshot #{screenshot_file}"
spectre.submit_test('About Us', 'Phantom', 'OSX', 1024, File.new(screenshot_file, 'rb'))
spectre.submit_test('About Us', 'Phantom', 'OSX', 1024, File.new(screenshot_file, 'rb'), "", "90%")
puts "Submitting #{screenshot_file}"
File.delete(screenshot_file)

Expand Down Expand Up @@ -101,5 +101,4 @@ if Rails.env.development?
gc.draw(image)
image.write 'homepage.png'
end

end
5 changes: 5 additions & 0 deletions spec/models/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
test = FactoryGirl.create(:test)
expect(test.five_consecutive_failures).to eq true
end

it 'should have a default fuzz level of 30%' do
test = FactoryGirl.create(:test)
expect(test.fuzz_level).to eq '30%'
end
end

0 comments on commit 4d54667

Please sign in to comment.