compaa 0.0.4 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +2 -3
  3. data/Gemfile +1 -1
  4. data/Rakefile +32 -8
  5. data/bin/compaa +1 -86
  6. data/compaa.gemspec +11 -14
  7. data/fixtures/homemove/artifacts/differences_in_screenshots_this_run/homemove/step_2_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png_difference.gif +0 -0
  8. data/fixtures/homemove/artifacts/differences_in_screenshots_this_run/homemove/step_4_contact_details/firefox_Darwin_sky_helpcentre_home_move_contact_details1.png_difference.gif +0 -0
  9. data/fixtures/homemove/artifacts/differences_in_screenshots_this_run/homemove/validation_failures_on_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png_difference.gif +0 -0
  10. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/chrome_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  11. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png +0 -0
  12. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/firefox_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  13. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/internet-explorer_8_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  14. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/internet-explorer_9_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  15. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_doesn_t_select_any_service/safari_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  16. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/chrome_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  17. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png +0 -0
  18. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/firefox_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  19. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/internet-explorer_7_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  20. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/internet-explorer_8_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  21. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/internet-explorer_9_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  22. data/fixtures/homemove/artifacts/reference_screenshots/homemove/customer_moving_to_a_new_home_in_ireland/safari_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  23. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/chrome_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  24. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/firefox_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  25. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/internet-explorer_7_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  26. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/internet-explorer_8_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  27. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/internet-explorer_9_Windows_sky_helpcentre_home_move_getting_started1.png +0 -0
  28. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_0_moving_home/safari_Mac_sky_helpcentre_home_move_getting_started1.png +0 -0
  29. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_1_moving_dates/chrome_Mac_sky_helpcentre_home_move_moving_dates1.png +0 -0
  30. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_1_moving_dates/firefox_Mac_sky_helpcentre_home_move_moving_dates1.png +0 -0
  31. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_1_moving_dates/internet-explorer_8_Windows_sky_helpcentre_home_move_moving_dates1.png +0 -0
  32. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_1_moving_dates/internet-explorer_9_Windows_sky_helpcentre_home_move_moving_dates1.png +0 -0
  33. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/chrome_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  34. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png +0 -0
  35. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/firefox_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  36. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/internet-explorer_8_Windows_sky_helpcentre_home_move_your_new_home1.png +0 -0
  37. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/internet-explorer_9_Windows_sky_helpcentre_home_move_your_new_home1.png +0 -0
  38. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_2_your_new_home/safari_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  39. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/chrome_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  40. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/firefox_Darwin_sky_helpcentre_home_move_tv_setup1.png +0 -0
  41. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/firefox_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  42. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/internet-explorer_8_Windows_sky_helpcentre_home_move_tv_setup1.png +0 -0
  43. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/internet-explorer_9_Windows_sky_helpcentre_home_move_tv_setup1.png +0 -0
  44. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_3_tv_setup/safari_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  45. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/chrome_Mac_sky_helpcentre_home_move_contact_details1.png +0 -0
  46. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/firefox_Darwin_sky_helpcentre_home_move_contact_details1.png +0 -0
  47. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/firefox_Mac_sky_helpcentre_home_move_contact_details1.png +0 -0
  48. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/internet-explorer_8_Windows_sky_helpcentre_home_move_contact_details1.png +0 -0
  49. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/internet-explorer_9_Windows_sky_helpcentre_home_move_contact_details1.png +0 -0
  50. data/fixtures/homemove/artifacts/reference_screenshots/homemove/step_4_contact_details/safari_Mac_sky_helpcentre_home_move_contact_details1.png +0 -0
  51. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/chrome_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  52. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/firefox_Darwin_sky_helpcentre_home_move_tv_setup1.png +0 -0
  53. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/firefox_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  54. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/internet-explorer_8_Windows_sky_helpcentre_home_move_tv_setup1.png +0 -0
  55. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/internet-explorer_9_Windows_sky_helpcentre_home_move_tv_setup1.png +0 -0
  56. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_tv_set_up/safari_Mac_sky_helpcentre_home_move_tv_setup1.png +0 -0
  57. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/chrome_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  58. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png +0 -0
  59. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/firefox_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  60. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/internet-explorer_8_Windows_sky_helpcentre_home_move_your_new_home1.png +0 -0
  61. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/internet-explorer_9_Windows_sky_helpcentre_home_move_your_new_home1.png +0 -0
  62. data/fixtures/homemove/artifacts/reference_screenshots/homemove/validation_failures_on_your_new_home/safari_Mac_sky_helpcentre_home_move_your_new_home1.png +0 -0
  63. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/customer_doesn_t_select_any_service/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png +0 -0
  64. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/customer_moving_to_a_new_home_in_ireland/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png +0 -0
  65. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/step_0_moving_home/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png +0 -0
  66. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/step_2_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png +0 -0
  67. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/step_3_tv_setup/firefox_Darwin_sky_helpcentre_home_move_tv_setup1.png +0 -0
  68. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/step_4_contact_details/firefox_Darwin_sky_helpcentre_home_move_contact_details1.png +0 -0
  69. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/validation_failures_on_tv_set_up/firefox_Darwin_sky_helpcentre_home_move_tv_setup1.png +0 -0
  70. data/fixtures/homemove/artifacts/screenshots_generated_this_run/homemove/validation_failures_on_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png +0 -0
  71. data/lib/assets/bootstrap.css +6158 -0
  72. data/lib/assets/compaa.js +153 -0
  73. data/lib/assets/index.haml +29 -0
  74. data/lib/assets/jquery-2.0.0.js +8755 -0
  75. data/lib/assets/underscore.js +1227 -0
  76. data/lib/compaa/generated_image.rb +5 -1
  77. data/lib/compaa/rack_app.rb +81 -30
  78. data/lib/compaa/version.rb +1 -1
  79. data/mock_app.rb +22 -0
  80. data/spec/integration/integration_spec.rb +66 -0
  81. data/spec/javascripts/CompaaSpec.js +81 -0
  82. data/spec/javascripts/fixtures/body.html +19 -0
  83. data/spec/javascripts/support/bind.js +23 -0
  84. data/spec/javascripts/support/jasmine-jquery.js +658 -0
  85. data/spec/javascripts/support/jasmine.yml +9 -0
  86. data/spec/javascripts/support/jasmine_helper.rb +11 -0
  87. data/spec/rack_app_spec.rb +101 -35
  88. data/spec/spec_helper.rb +2 -2
  89. metadata +196 -88
  90. data/features/compaa.feature +0 -38
  91. data/features/step_definitions/compaa_steps.rb +0 -51
  92. data/features/support/env.rb +0 -27
  93. data/features/support/file_helpers.rb +0 -23
  94. data/features/support/matchers.rb +0 -13
  95. data/lib/compaa/script.js +0 -77
  96. data/lib/compaa/template.haml +0 -20
  97. data/lib/watir-webdriver-fake.rb +0 -9
@@ -25,7 +25,11 @@ module Compaa
25
25
  def delete_difference_image
26
26
  difference_image_path = path.gsub 'screenshots_generated_this_run', 'differences_in_screenshots_this_run'
27
27
  difference_image_path << '_difference.gif'
28
- file_manager.rm difference_image_path
28
+ file_manager.rm difference_image_path, force: true
29
+ end
30
+
31
+ def delete
32
+ file_manager.rm path
29
33
  end
30
34
 
31
35
  private
@@ -1,41 +1,92 @@
1
1
  require 'rack'
2
2
  require 'haml'
3
+ require 'json'
3
4
 
4
5
  module Compaa
5
6
  class RackApp
6
- attr_writer :root_directory
7
+ class << self
8
+ alias :new! :new
9
+ end
7
10
 
8
- DEFAULT_ROOT = Dir.pwd
11
+ def self.new
12
+ me = self
13
+ Rack::Builder.new do
14
+ use Rack::Static, :urls => ['/artifacts/'], :root => Dir.pwd
15
+ use Rack::Static, :urls => ['/assets'], :root => File.expand_path('..', File.dirname(__FILE__))
16
+ run(me.new!)
17
+ end
18
+ end
9
19
 
10
- def app
11
- template = File.read File.expand_path 'template.haml', File.dirname(__FILE__)
12
- root = @root_directory or DEFAULT_ROOT
20
+ def call(env)
21
+ request = Request.new(Rack::Request.new(env))
22
+ request.response
23
+ end
13
24
 
14
- Rack::Builder.new do
15
- use Rack::Static, :urls => ['/artifacts'], :root => root
16
-
17
- run lambda { |env|
18
- request = Rack::Request.new env
19
-
20
- if request.path == '/' and request.params.has_key? 'filepath'
21
- locals = { :filepath => request.params['filepath'] }
22
- body = Haml::Engine.new(template).render Object.new, locals
23
-
24
- [ 200, { 'Content-Type' => 'text/html' }, [body] ]
25
- elsif request.path == '/script.js'
26
- js = File.read File.expand_path('script.js', File.dirname(__FILE__))
27
-
28
- [ 200, { 'Content-Type' => 'application/javascript' }, [js] ]
29
- elsif request.path == '/screenshots' and request.request_method == 'POST' and request.params.has_key? 'filepath'
30
- generated_image = GeneratedImage.new File.join(root, request.params['filepath'])
31
- generated_image.create_reference_image
32
- generated_image.delete_difference_image
33
-
34
- [ 200, { 'Content-Type' => 'text/plain' }, ['Success'] ]
35
- else
36
- [ 404, {}, ['Not found'] ]
37
- end
38
- }
25
+ class Request
26
+ def initialize(request)
27
+ @request = request
28
+ end
29
+
30
+ def response
31
+ case @request.request_method
32
+ when 'GET' then get
33
+ when 'POST' then post
34
+ else four_oh_four
35
+ end
36
+ end
37
+
38
+ def get
39
+ case @request.path
40
+ when '/' then index
41
+ when '/artifacts.json' then artifacts_json
42
+ else four_oh_four
43
+ end
44
+ end
45
+
46
+ def post
47
+ if @request.path == '/screenshots'
48
+ screenshots
49
+ else
50
+ four_oh_four
51
+ end
52
+ end
53
+
54
+ def index
55
+ template = File.read File.expand_path '../assets/index.haml', File.dirname(__FILE__)
56
+ body = Haml::Engine.new(template).render
57
+
58
+ [ 200, { 'Content-Type' => 'text/html' }, [body] ]
59
+ end
60
+
61
+ def screenshots
62
+ if @request.params.has_key?('filepath')
63
+ path = File.join(Dir.pwd, @request.params['filepath'])
64
+ generated_image = GeneratedImage.new(path)
65
+
66
+ generated_image.create_reference_image
67
+
68
+ generated_image.delete_difference_image
69
+ generated_image.delete
70
+
71
+ [ 200, { 'Content-Type' => 'text/plain' }, ['Success'] ]
72
+ else
73
+ four_oh_four
74
+ end
75
+ end
76
+
77
+ def artifacts_json
78
+ difference_images = DifferenceImage.all.map(&:reference_path)
79
+ generated_images = GeneratedImage.all.reject(&:has_reference_image?).map(&:reference_path)
80
+
81
+ json = {
82
+ artifacts: difference_images + generated_images
83
+ }.to_json
84
+
85
+ [ 200, { 'Content-Type' => 'application/json' }, [json] ]
86
+ end
87
+
88
+ def four_oh_four
89
+ [ 404, { 'Content-Type' => 'text/plain' }, ['Not found'] ]
39
90
  end
40
91
  end
41
92
  end
@@ -1,3 +1,3 @@
1
1
  module Compaa
2
- VERSION = "0.0.4"
2
+ VERSION = '0.1.1'
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'sinatra'
2
+ require 'json'
3
+ require 'rack/cors'
4
+
5
+ use Rack::Cors do
6
+ allow do
7
+ origins '*'
8
+ resource '/*', :headers => :any, :methods => [:get, :post]
9
+ end
10
+ end
11
+
12
+ get '/artifacts.json' do
13
+ content_type 'application/json'
14
+ {
15
+ artifacts: %w(
16
+ artifacts/reference_screenshots/one.png
17
+ artifacts/reference_screenshots/two.png
18
+ artifacts/reference_screenshots/three.png
19
+ artifacts/reference_screenshots/four.png
20
+ )
21
+ }.to_json
22
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'capybara/poltergeist'
3
+
4
+ Dir.chdir 'tmp/homemove' do
5
+ Capybara.app = Compaa::RackApp.new
6
+ end
7
+ Capybara.current_driver = :selenium
8
+
9
+ describe "accepting screenshots from the browser" do
10
+ include Capybara::DSL
11
+
12
+ before do
13
+ FileUtils.rm_rf('tmp/homemove')
14
+ FileUtils.cp_r('fixtures/homemove', 'tmp/')
15
+ end
16
+
17
+ def assert_file_deleted(path)
18
+ refute File.exists?(path), 'Difference image was not deleted'
19
+ end
20
+
21
+ def refute_file_deleted(path)
22
+ assert File.exists?(path), 'Difference image should not have been deleted but was'
23
+ end
24
+
25
+ it "Accepts via clicking accept" do
26
+ Dir.chdir 'tmp/homemove' do
27
+ homemove_dir = 'artifacts/differences_in_screenshots_this_run/homemove'
28
+ visit '/'
29
+
30
+ assert_match %r{#{homemove_dir}/step_2_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1\.png_difference\.gif$},
31
+ page.find('img#animation', visible: false)['src']
32
+
33
+ click_link 'Accept'
34
+ sleep 0.1
35
+
36
+ assert_file_deleted "#{homemove_dir}/step_2_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png_difference.gif"
37
+
38
+ assert_match %r{#{homemove_dir}/step_4_contact_details/firefox_Darwin_sky_helpcentre_home_move_contact_details1\.png_difference\.gif$},
39
+ page.find('img#animation', visible: false)['src']
40
+
41
+ click_link 'Reject'
42
+ sleep 0.1
43
+
44
+ refute_file_deleted "#{homemove_dir}/step_4_contact_details/firefox_Darwin_sky_helpcentre_home_move_contact_details1.png_difference.gif"
45
+
46
+ assert_match %r{#{homemove_dir}/validation_failures_on_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1\.png_difference\.gif$},
47
+ page.find('img#animation', visible: false)['src']
48
+
49
+ click_link 'Accept'
50
+ sleep 0.1
51
+
52
+ assert_file_deleted "#{homemove_dir}/validation_failures_on_your_new_home/firefox_Darwin_sky_helpcentre_home_move_your_new_home1.png_difference.gif"
53
+
54
+ assert_match %r{artifacts/screenshots_generated_this_run/homemove/step_0_moving_home/firefox_Darwin_sky_helpcentre_home_move_getting_started1\.png$},
55
+ page.find('img#generatedImage', visible: false)['src']
56
+
57
+ click_link 'Accept'
58
+ sleep 0.5
59
+
60
+ assert File.exists? "artifacts/reference_screenshots/homemove/step_0_moving_home/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png"
61
+ assert_file_deleted "artifacts/screenshots_generated_this_run/homemove/step_0_moving_home/firefox_Darwin_sky_helpcentre_home_move_getting_started1.png"
62
+
63
+ assert page.has_selector?('h1', text: 'Done!')
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,81 @@
1
+ describe("Compaa", function() {
2
+ var compaa;
3
+
4
+ beforeEach(function() {
5
+ compaa = Object.create(Compaa);
6
+ compaa.compaaHost = 'http://localhost:4567';
7
+ loadFixtures('body.html');
8
+ });
9
+
10
+ describe("generatedImagePath()", function() {
11
+ it("changes the directory and filename of the referenceImagePath", function() {
12
+ var referencePath, expectedGeneratedImagePath;
13
+
14
+ referencePath = 'artifacts/reference_screenshots/firefox_home_move.png'
15
+ expectedGeneratedImagePath = 'artifacts/screenshots_generated_this_run/firefox_home_move.png';
16
+
17
+ spyOn(compaa, 'referenceImagePath').andReturn(referencePath);
18
+
19
+ expect(compaa.generatedImagePath()).toEqual(expectedGeneratedImagePath);
20
+ });
21
+ });
22
+
23
+ describe("differenceGifPath()", function() {
24
+ it("changes the directory to screenshots_generated_this_run and adds a png extension", function() {
25
+ var referenceImagePath, expectedDifferenceGifPath;
26
+
27
+ expectedDifferenceGifPath = 'artifacts/differences_in_screenshots_this_run/firefox_home_move.png_difference.gif';
28
+ referenceImagePath = 'artifacts/reference_screenshots/firefox_home_move.png'
29
+
30
+ spyOn(compaa, 'referenceImagePath').andReturn(referenceImagePath);
31
+
32
+ expect(compaa.differenceGifPath()).toEqual(expectedDifferenceGifPath);
33
+ });
34
+ });
35
+
36
+ describe("show()", function() {
37
+ it("hides [difference animation referenceImage generatedImage] elements and shows the given element", function() {
38
+ compaa.show('difference');
39
+
40
+ expect($('#difference').css('display')).toEqual('inline');
41
+
42
+ expect($('#animation').css('display')).toEqual('none');
43
+ expect($('#referenceImage').css('display')).toEqual('none');
44
+ expect($('#generatedImage').css('display')).toEqual('none');
45
+ });
46
+
47
+ it("hides [difference animation referenceImage generatedImage] elements and shows the given element", function() {
48
+ compaa.show('generatedImage');
49
+
50
+ expect($('#difference').css('display')).toEqual('none');
51
+ expect($('#animation').css('display')).toEqual('none');
52
+ expect($('#referenceImage').css('display')).toEqual('none');
53
+ expect($('#generatedImage').css('display')).toEqual('inline');
54
+ });
55
+ });
56
+
57
+ describe("init", function() {
58
+ it("sets click handlers for buttons", function() {
59
+ compaa.init();
60
+ $('#differenceButton').click();
61
+ expect($('#difference')).not.toBeHidden();
62
+ expect($('#animation')).toBeHidden();
63
+ });
64
+
65
+ it("sets reference images", function() {
66
+ spyOn(compaa, 'setArtifacts').andCallThrough();
67
+ compaa.init();
68
+ waitsFor(function() {
69
+ return compaa.setArtifacts.callCount > 0;
70
+ }, 'setArtifacts() didnt get called, is the mock is running??');
71
+ runs(function() {
72
+ expect(compaa.artifacts).toEqual([
73
+ 'artifacts/reference_screenshots/one.png',
74
+ 'artifacts/reference_screenshots/two.png',
75
+ 'artifacts/reference_screenshots/three.png',
76
+ 'artifacts/reference_screenshots/four.png'
77
+ ]);
78
+ });
79
+ });
80
+ });
81
+ });
@@ -0,0 +1,19 @@
1
+ <div id="fixture">
2
+ <canvas id='offScreenCanvas' style='position: absolute; left: -9999999px;'></canvas>
3
+ <canvas id='difference'></canvas>
4
+ <img id='animation' style='display: none'>
5
+ <img id='referenceImage' style='display: none'>
6
+ <img id='generatedImage' style='display: none'>
7
+ <div style='width: 500px; margin: 0px auto; text-align: center;'>
8
+ <p>
9
+ <a class='btn' href='#' id='differenceButton'>Difference</a>
10
+ <a class='btn' href='#' id='animationButton'>Animation</a>
11
+ <a class='btn' href='#' id='referenceImageButton'>Reference Image</a>
12
+ <a class='btn' href='#' id='generatedImageButton'>Generated Image</a>
13
+ </p>
14
+ <p>
15
+ <a class='btn btn-primary' href='#' id='accept'>Accept</a>
16
+ <a class='btn btn-danger' href='#' id='reject'>Reject</a>
17
+ </p>
18
+ </div>
19
+ </div>
@@ -0,0 +1,23 @@
1
+ if (!Function.prototype.bind) {
2
+ Function.prototype.bind = function (oThis) {
3
+ if (typeof this !== "function") {
4
+ // closest thing possible to the ECMAScript 5 internal IsCallable function
5
+ throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
6
+ }
7
+
8
+ var aArgs = Array.prototype.slice.call(arguments, 1),
9
+ fToBind = this,
10
+ fNOP = function () {},
11
+ fBound = function () {
12
+ return fToBind.apply(this instanceof function() {} && oThis
13
+ ? this
14
+ : oThis,
15
+ aArgs.concat(Array.prototype.slice.call(arguments)));
16
+ };
17
+
18
+ fNOP.prototype = this.prototype;
19
+ fBound.prototype = new fNOP();
20
+
21
+ return fBound;
22
+ };
23
+ }
@@ -0,0 +1,658 @@
1
+ /*!
2
+ Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
3
+
4
+ Version 1.5.1
5
+
6
+ https://github.com/velesin/jasmine-jquery
7
+
8
+ Copyright (c) 2010-2013 Wojciech Zawistowski, Travis Jeffery
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining
11
+ a copy of this software and associated documentation files (the
12
+ "Software"), to deal in the Software without restriction, including
13
+ without limitation the rights to use, copy, modify, merge, publish,
14
+ distribute, sublicense, and/or sell copies of the Software, and to
15
+ permit persons to whom the Software is furnished to do so, subject to
16
+ the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be
19
+ included in all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ */
29
+ var readFixtures = function() {
30
+ return jasmine.getFixtures().proxyCallTo_('read', arguments)
31
+ }
32
+
33
+ var preloadFixtures = function() {
34
+ jasmine.getFixtures().proxyCallTo_('preload', arguments)
35
+ }
36
+
37
+ var loadFixtures = function() {
38
+ jasmine.getFixtures().proxyCallTo_('load', arguments)
39
+ }
40
+
41
+ var appendLoadFixtures = function() {
42
+ jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
43
+ }
44
+
45
+ var setFixtures = function(html) {
46
+ jasmine.getFixtures().proxyCallTo_('set', arguments)
47
+ }
48
+
49
+ var appendSetFixtures = function() {
50
+ jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
51
+ }
52
+
53
+ var sandbox = function(attributes) {
54
+ return jasmine.getFixtures().sandbox(attributes)
55
+ }
56
+
57
+ var spyOnEvent = function(selector, eventName) {
58
+ return jasmine.JQuery.events.spyOn(selector, eventName)
59
+ }
60
+
61
+ var preloadStyleFixtures = function() {
62
+ jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
63
+ }
64
+
65
+ var loadStyleFixtures = function() {
66
+ jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
67
+ }
68
+
69
+ var appendLoadStyleFixtures = function() {
70
+ jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
71
+ }
72
+
73
+ var setStyleFixtures = function(html) {
74
+ jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
75
+ }
76
+
77
+ var appendSetStyleFixtures = function(html) {
78
+ jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
79
+ }
80
+
81
+ var loadJSONFixtures = function() {
82
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
83
+ }
84
+
85
+ var getJSONFixture = function(url) {
86
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
87
+ }
88
+
89
+ jasmine.spiedEventsKey = function (selector, eventName) {
90
+ return [$(selector).selector, eventName].toString()
91
+ }
92
+
93
+ jasmine.getFixtures = function() {
94
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
95
+ }
96
+
97
+ jasmine.getStyleFixtures = function() {
98
+ return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
99
+ }
100
+
101
+ jasmine.Fixtures = function() {
102
+ this.containerId = 'jasmine-fixtures'
103
+ this.fixturesCache_ = {}
104
+ this.fixturesPath = 'spec/javascripts/fixtures'
105
+ }
106
+
107
+ jasmine.Fixtures.prototype.set = function(html) {
108
+ this.cleanUp()
109
+ this.createContainer_(html)
110
+ }
111
+
112
+ jasmine.Fixtures.prototype.appendSet= function(html) {
113
+ this.addToContainer_(html)
114
+ }
115
+
116
+ jasmine.Fixtures.prototype.preload = function() {
117
+ this.read.apply(this, arguments)
118
+ }
119
+
120
+ jasmine.Fixtures.prototype.load = function() {
121
+ this.cleanUp()
122
+ this.createContainer_(this.read.apply(this, arguments))
123
+ }
124
+
125
+ jasmine.Fixtures.prototype.appendLoad = function() {
126
+ this.addToContainer_(this.read.apply(this, arguments))
127
+ }
128
+
129
+ jasmine.Fixtures.prototype.read = function() {
130
+ var htmlChunks = []
131
+
132
+ var fixtureUrls = arguments
133
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
134
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
135
+ }
136
+
137
+ return htmlChunks.join('')
138
+ }
139
+
140
+ jasmine.Fixtures.prototype.clearCache = function() {
141
+ this.fixturesCache_ = {}
142
+ }
143
+
144
+ jasmine.Fixtures.prototype.cleanUp = function() {
145
+ $('#' + this.containerId).remove()
146
+ }
147
+
148
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
149
+ var attributesToSet = attributes || {}
150
+ return $('<div id="sandbox" />').attr(attributesToSet)
151
+ }
152
+
153
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
154
+ var container
155
+ if(html instanceof $) {
156
+ container = $('<div id="' + this.containerId + '" />')
157
+ container.html(html)
158
+ } else {
159
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
160
+ }
161
+ $(document.body).append(container)
162
+ }
163
+
164
+ jasmine.Fixtures.prototype.addToContainer_ = function(html){
165
+ var container = $(document.body).find('#'+this.containerId).append(html)
166
+ if(!container.length){
167
+ this.createContainer_(html)
168
+ }
169
+ }
170
+
171
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
172
+ if (typeof this.fixturesCache_[url] === 'undefined') {
173
+ this.loadFixtureIntoCache_(url)
174
+ }
175
+ return this.fixturesCache_[url]
176
+ }
177
+
178
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
179
+ var url = this.makeFixtureUrl_(relativeUrl)
180
+ var request = $.ajax({
181
+ type: "GET",
182
+ url: url + "?" + new Date().getTime(),
183
+ async: false
184
+ })
185
+ this.fixturesCache_[relativeUrl] = request.responseText
186
+ }
187
+
188
+ jasmine.Fixtures.prototype.makeFixtureUrl_ = function(relativeUrl){
189
+ return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
190
+ }
191
+
192
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
193
+ return this[methodName].apply(this, passedArguments)
194
+ }
195
+
196
+
197
+ jasmine.StyleFixtures = function() {
198
+ this.fixturesCache_ = {}
199
+ this.fixturesNodes_ = []
200
+ this.fixturesPath = 'spec/javascripts/fixtures'
201
+ }
202
+
203
+ jasmine.StyleFixtures.prototype.set = function(css) {
204
+ this.cleanUp()
205
+ this.createStyle_(css)
206
+ }
207
+
208
+ jasmine.StyleFixtures.prototype.appendSet = function(css) {
209
+ this.createStyle_(css)
210
+ }
211
+
212
+ jasmine.StyleFixtures.prototype.preload = function() {
213
+ this.read_.apply(this, arguments)
214
+ }
215
+
216
+ jasmine.StyleFixtures.prototype.load = function() {
217
+ this.cleanUp()
218
+ this.createStyle_(this.read_.apply(this, arguments))
219
+ }
220
+
221
+ jasmine.StyleFixtures.prototype.appendLoad = function() {
222
+ this.createStyle_(this.read_.apply(this, arguments))
223
+ }
224
+
225
+ jasmine.StyleFixtures.prototype.cleanUp = function() {
226
+ while(this.fixturesNodes_.length) {
227
+ this.fixturesNodes_.pop().remove()
228
+ }
229
+ }
230
+
231
+ jasmine.StyleFixtures.prototype.createStyle_ = function(html) {
232
+ var styleText = $('<div></div>').html(html).text(),
233
+ style = $('<style>' + styleText + '</style>')
234
+
235
+ this.fixturesNodes_.push(style)
236
+
237
+ $('head').append(style)
238
+ }
239
+
240
+ jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
241
+
242
+ jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
243
+
244
+ jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
245
+
246
+ jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
247
+
248
+ jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
249
+
250
+ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
251
+
252
+ jasmine.getJSONFixtures = function() {
253
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
254
+ }
255
+
256
+ jasmine.JSONFixtures = function() {
257
+ this.fixturesCache_ = {}
258
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
259
+ }
260
+
261
+ jasmine.JSONFixtures.prototype.load = function() {
262
+ this.read.apply(this, arguments)
263
+ return this.fixturesCache_
264
+ }
265
+
266
+ jasmine.JSONFixtures.prototype.read = function() {
267
+ var fixtureUrls = arguments
268
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
269
+ this.getFixtureData_(fixtureUrls[urlIndex])
270
+ }
271
+ return this.fixturesCache_
272
+ }
273
+
274
+ jasmine.JSONFixtures.prototype.clearCache = function() {
275
+ this.fixturesCache_ = {}
276
+ }
277
+
278
+ jasmine.JSONFixtures.prototype.getFixtureData_ = function(url) {
279
+ this.loadFixtureIntoCache_(url)
280
+ return this.fixturesCache_[url]
281
+ }
282
+
283
+ jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
284
+ var self = this
285
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
286
+ $.ajax({
287
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
288
+ cache: false,
289
+ dataType: 'json',
290
+ url: url,
291
+ success: function(data) {
292
+ self.fixturesCache_[relativeUrl] = data
293
+ },
294
+ error: function(jqXHR, status, errorThrown) {
295
+ throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
296
+ }
297
+ })
298
+ }
299
+
300
+ jasmine.JSONFixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
301
+ return this[methodName].apply(this, passedArguments)
302
+ }
303
+
304
+ jasmine.JQuery = function() {}
305
+
306
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
307
+ return $('<div/>').append(html).html()
308
+ }
309
+
310
+ jasmine.JQuery.elementToString = function(element) {
311
+ var domEl = $(element).get(0)
312
+ if (domEl == undefined || domEl.cloneNode)
313
+ return $('<div />').append($(element).clone()).html()
314
+ else
315
+ return element.toString()
316
+ }
317
+
318
+ jasmine.JQuery.matchersClass = {}
319
+
320
+ !function(namespace) {
321
+ var data = {
322
+ spiedEvents: {},
323
+ handlers: []
324
+ }
325
+
326
+ namespace.events = {
327
+ spyOn: function(selector, eventName) {
328
+ var handler = function(e) {
329
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments)
330
+ }
331
+ $(selector).on(eventName, handler)
332
+ data.handlers.push(handler)
333
+ return {
334
+ selector: selector,
335
+ eventName: eventName,
336
+ handler: handler,
337
+ reset: function(){
338
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
339
+ }
340
+ }
341
+ },
342
+
343
+ args: function(selector, eventName) {
344
+ var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)];
345
+
346
+ if (!actualArgs) {
347
+ throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent.";
348
+ }
349
+
350
+ return actualArgs;
351
+ },
352
+
353
+ wasTriggered: function(selector, eventName) {
354
+ return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
355
+ },
356
+
357
+ wasTriggeredWith: function(selector, eventName, expectedArgs, env) {
358
+ var actualArgs = jasmine.JQuery.events.args(selector, eventName).slice(1);
359
+ if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') {
360
+ actualArgs = actualArgs[0];
361
+ }
362
+ return env.equals_(expectedArgs, actualArgs);
363
+ },
364
+
365
+ wasPrevented: function(selector, eventName) {
366
+ var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)],
367
+ e = args ? args[0] : undefined;
368
+ return e && e.isDefaultPrevented()
369
+ },
370
+
371
+ wasStopped: function(selector, eventName) {
372
+ var e;
373
+ return (e = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]) && e.isPropagationStopped()
374
+ },
375
+
376
+ cleanUp: function() {
377
+ data.spiedEvents = {}
378
+ data.handlers = []
379
+ }
380
+ }
381
+ }(jasmine.JQuery)
382
+
383
+ !function(){
384
+ var jQueryMatchers = {
385
+ toHaveClass: function(className) {
386
+ return this.actual.hasClass(className)
387
+ },
388
+
389
+ toHaveCss: function(css){
390
+ for (var prop in css){
391
+ if (this.actual.css(prop) !== css[prop]) return false
392
+ }
393
+ return true
394
+ },
395
+
396
+ toBeVisible: function() {
397
+ return this.actual.is(':visible')
398
+ },
399
+
400
+ toBeHidden: function() {
401
+ return this.actual.is(':hidden')
402
+ },
403
+
404
+ toBeSelected: function() {
405
+ return this.actual.is(':selected')
406
+ },
407
+
408
+ toBeChecked: function() {
409
+ return this.actual.is(':checked')
410
+ },
411
+
412
+ toBeEmpty: function() {
413
+ return this.actual.is(':empty')
414
+ },
415
+
416
+ toExist: function() {
417
+ return $(document).find(this.actual).length
418
+ },
419
+
420
+ toHaveLength: function(length) {
421
+ return this.actual.length === length
422
+ },
423
+
424
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
425
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
426
+ },
427
+
428
+ toHaveProp: function(propertyName, expectedPropertyValue) {
429
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
430
+ },
431
+
432
+ toHaveId: function(id) {
433
+ return this.actual.attr('id') == id
434
+ },
435
+
436
+ toHaveHtml: function(html) {
437
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
438
+ },
439
+
440
+ toContainHtml: function(html){
441
+ var actualHtml = this.actual.html()
442
+ var expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
443
+ return (actualHtml.indexOf(expectedHtml) >= 0)
444
+ },
445
+
446
+ toHaveText: function(text) {
447
+ var trimmedText = $.trim(this.actual.text())
448
+ if (text && $.isFunction(text.test)) {
449
+ return text.test(trimmedText)
450
+ } else {
451
+ return trimmedText == text
452
+ }
453
+ },
454
+
455
+ toContainText: function(text) {
456
+ var trimmedText = $.trim(this.actual.text())
457
+ if (text && $.isFunction(text.test)) {
458
+ return text.test(trimmedText)
459
+ } else {
460
+ return trimmedText.indexOf(text) != -1;
461
+ }
462
+ },
463
+
464
+ toHaveValue: function(value) {
465
+ return this.actual.val() === value
466
+ },
467
+
468
+ toHaveData: function(key, expectedValue) {
469
+ return hasProperty(this.actual.data(key), expectedValue)
470
+ },
471
+
472
+ toBe: function(selector) {
473
+ return this.actual.is(selector)
474
+ },
475
+
476
+ toContain: function(selector) {
477
+ return this.actual.find(selector).length
478
+ },
479
+
480
+ toBeDisabled: function(selector){
481
+ return this.actual.is(':disabled')
482
+ },
483
+
484
+ toBeFocused: function(selector) {
485
+ return this.actual[0] === this.actual[0].ownerDocument.activeElement
486
+ },
487
+
488
+ toHandle: function(event) {
489
+
490
+ var events = $._data(this.actual.get(0), "events")
491
+
492
+ if(!events || !event || typeof event !== "string") {
493
+ return false
494
+ }
495
+
496
+ var namespaces = event.split(".")
497
+ var eventType = namespaces.shift()
498
+ var sortedNamespaces = namespaces.slice(0).sort()
499
+ var namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
500
+
501
+ if(events[eventType] && namespaces.length) {
502
+ for(var i = 0; i < events[eventType].length; i++) {
503
+ var namespace = events[eventType][i].namespace
504
+ if(namespaceRegExp.test(namespace)) {
505
+ return true
506
+ }
507
+ }
508
+ } else {
509
+ return events[eventType] && events[eventType].length > 0
510
+ }
511
+ },
512
+
513
+ // tests the existence of a specific event binding + handler
514
+ toHandleWith: function(eventName, eventHandler) {
515
+ var stack = $._data(this.actual.get(0), "events")[eventName]
516
+ for (var i = 0; i < stack.length; i++) {
517
+ if (stack[i].handler == eventHandler) return true
518
+ }
519
+ return false
520
+ }
521
+ }
522
+
523
+ var hasProperty = function(actualValue, expectedValue) {
524
+ if (expectedValue === undefined) return actualValue !== undefined
525
+ return actualValue == expectedValue
526
+ }
527
+
528
+ var bindMatcher = function(methodName) {
529
+ var builtInMatcher = jasmine.Matchers.prototype[methodName]
530
+
531
+ jasmine.JQuery.matchersClass[methodName] = function() {
532
+ if (this.actual
533
+ && (this.actual instanceof $
534
+ || jasmine.isDomNode(this.actual))) {
535
+ this.actual = $(this.actual)
536
+ var result = jQueryMatchers[methodName].apply(this, arguments)
537
+ var element
538
+ if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
539
+ this.actual = jasmine.JQuery.elementToString(this.actual)
540
+ return result
541
+ }
542
+
543
+ if (builtInMatcher) {
544
+ return builtInMatcher.apply(this, arguments)
545
+ }
546
+
547
+ return false
548
+ }
549
+ }
550
+
551
+ for(var methodName in jQueryMatchers) {
552
+ bindMatcher(methodName)
553
+ }
554
+ }()
555
+
556
+ beforeEach(function() {
557
+ this.addMatchers(jasmine.JQuery.matchersClass)
558
+ this.addMatchers({
559
+ toHaveBeenTriggeredOn: function(selector) {
560
+ this.message = function() {
561
+ return [
562
+ "Expected event " + this.actual + " to have been triggered on " + selector,
563
+ "Expected event " + this.actual + " not to have been triggered on " + selector
564
+ ]
565
+ }
566
+ return jasmine.JQuery.events.wasTriggered(selector, this.actual)
567
+ }
568
+ })
569
+ this.addMatchers({
570
+ toHaveBeenTriggered: function(){
571
+ var eventName = this.actual.eventName,
572
+ selector = this.actual.selector
573
+ this.message = function() {
574
+ return [
575
+ "Expected event " + eventName + " to have been triggered on " + selector,
576
+ "Expected event " + eventName + " not to have been triggered on " + selector
577
+ ]
578
+ }
579
+ return jasmine.JQuery.events.wasTriggered(selector, eventName)
580
+ }
581
+ })
582
+ this.addMatchers({
583
+ toHaveBeenTriggeredOnAndWith: function() {
584
+ var selector = arguments[0],
585
+ expectedArgs = arguments[1],
586
+ wasTriggered = jasmine.JQuery.events.wasTriggered(selector, this.actual);
587
+ this.message = function() {
588
+ if (wasTriggered) {
589
+ var actualArgs = jasmine.JQuery.events.args(selector, this.actual, expectedArgs)[1];
590
+ return [
591
+ "Expected event " + this.actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs),
592
+ "Expected event " + this.actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
593
+ ]
594
+ } else {
595
+ return [
596
+ "Expected event " + this.actual + " to have been triggered on " + selector,
597
+ "Expected event " + this.actual + " not to have been triggered on " + selector
598
+ ]
599
+ }
600
+ }
601
+ return wasTriggered && jasmine.JQuery.events.wasTriggeredWith(selector, this.actual, expectedArgs, this.env);
602
+ }
603
+ })
604
+ this.addMatchers({
605
+ toHaveBeenPreventedOn: function(selector) {
606
+ this.message = function() {
607
+ return [
608
+ "Expected event " + this.actual + " to have been prevented on " + selector,
609
+ "Expected event " + this.actual + " not to have been prevented on " + selector
610
+ ]
611
+ }
612
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual)
613
+ }
614
+ })
615
+ this.addMatchers({
616
+ toHaveBeenPrevented: function() {
617
+ var eventName = this.actual.eventName,
618
+ selector = this.actual.selector
619
+ this.message = function() {
620
+ return [
621
+ "Expected event " + eventName + " to have been prevented on " + selector,
622
+ "Expected event " + eventName + " not to have been prevented on " + selector
623
+ ]
624
+ }
625
+ return jasmine.JQuery.events.wasPrevented(selector, eventName)
626
+ }
627
+ })
628
+ this.addMatchers({
629
+ toHaveBeenStoppedOn: function(selector) {
630
+ this.message = function() {
631
+ return [
632
+ "Expected event " + this.actual + " to have been stopped on " + selector,
633
+ "Expected event " + this.actual + " not to have been stopped on " + selector
634
+ ]
635
+ }
636
+ return jasmine.JQuery.events.wasStopped(selector, this.actual)
637
+ }
638
+ })
639
+ this.addMatchers({
640
+ toHaveBeenStopped: function() {
641
+ var eventName = this.actual.eventName,
642
+ selector = this.actual.selector
643
+ this.message = function() {
644
+ return [
645
+ "Expected event " + eventName + " to have been stopped on " + selector,
646
+ "Expected event " + eventName + " not to have been stopped on " + selector
647
+ ]
648
+ }
649
+ return jasmine.JQuery.events.wasStopped(selector, eventName)
650
+ }
651
+ })
652
+ })
653
+
654
+ afterEach(function() {
655
+ jasmine.getFixtures().cleanUp()
656
+ jasmine.getStyleFixtures().cleanUp()
657
+ jasmine.JQuery.events.cleanUp()
658
+ })