integration-diff 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a238c08a8c42c20475b99d034b2560c1d97fdf8
4
+ data.tar.gz: 5e49985f73ffc19895cb45de6088716e7917547b
5
+ SHA512:
6
+ metadata.gz: 8f558f62dc340c5d0cc9b5d12b0aacac6a8733f9607c8040d27e11e77e3bff44c1ca59b127d701dc0f3f4059401dbc11db6ae82e7fa397b30eb180282d134142
7
+ data.tar.gz: 42f96558e1982174434c2a15dbee7af0cd00b082d2e69866f3091b404669581fe1026010d00e29bee2d571ed904455fb292c49370ef63b815dc526c0fe3c077a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Yuva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'IntegrationDiff'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
data/Readme.md ADDED
@@ -0,0 +1,75 @@
1
+ # IntegrationDiff
2
+
3
+ Currently this supports only RSpec.
4
+
5
+ ### Installation
6
+
7
+ ```rb
8
+ gem "integration-diff-rails", git: "git@github.com:code-mancers/integration-diff-rails"
9
+ ```
10
+
11
+ ### Configuration
12
+
13
+ Include `integration-diff-rails` in your rspec `spec_helper` and configure 6 variables
14
+ which will be used while taking screenshots. Make sure that `enable_service` is set to
15
+ to true if images need to be uploaded.
16
+
17
+ **NOTE:** Make sure that that project exists in service with `project_name`. Also
18
+ api key can be obtained by loggin into service and visiting `/api_key`.
19
+
20
+
21
+ ```rb
22
+ IntegrationDiff.configure do |config|
23
+ # configure domain to which all images have to be uploaded.
24
+ config.base_uri = "http://idf.dev"
25
+
26
+ # configure project name to which images belong to.
27
+ config.project_name = "idf"
28
+
29
+ # configure api_key required to authorize api access
30
+ config.api_key = ENV["IDIFF_API_KEY"]
31
+
32
+ # configure js driver which is used for taking screenshots.
33
+ config.javascript_driver = "poltergeist"
34
+
35
+ # configure service to mock capturing and uploading screenshots
36
+ config.enable_service = !!ENV["IDIFF_ENABLE"]
37
+
38
+ # configure logger to log messages. optional.
39
+ config.logger = Rails.logger
40
+ end
41
+ ```
42
+
43
+ After configuration, include `IntegrationDiff::Dsl` in your `spec_helper` and
44
+ configure before and after suite so that suite interacts with the service.
45
+
46
+
47
+ ```rb
48
+ RSpec.configure do |config|
49
+ config.include IntegrationDiff::Dsl
50
+
51
+ config.before(:suite) do
52
+ IntegrationDiff.start_run
53
+ end
54
+
55
+ config.after(:suite) do
56
+ IntegrationDiff.wrap_run
57
+ end
58
+ end
59
+ ```
60
+
61
+ ### Usage
62
+
63
+ In your specs, simply use `idiff` helper. make sure that you pass unique identifier
64
+ to screenshots that you take. unique identifier helps in differentiating this
65
+ screenshot taken from other screenshots.
66
+
67
+
68
+ ```rb
69
+ describe "Landing page" do
70
+ it "has a big banner" do
71
+ visit root_path
72
+ idiff.screenshot("unique-identifier")
73
+ end
74
+ end
75
+ ```
@@ -0,0 +1 @@
1
+ require 'integration_diff'
@@ -0,0 +1,22 @@
1
+ module IntegrationDiff
2
+ module Dsl
3
+ def self.idiff
4
+ @idiff ||=
5
+ begin
6
+ klass =
7
+ if IntegrationDiff.enable_service
8
+ IntegrationDiff::Runner
9
+ else
10
+ IntegrationDiff::DummyRunner
11
+ end
12
+
13
+ IntegrationDiff.logger.info "Using runner #{klass}"
14
+ klass.instance
15
+ end
16
+ end
17
+
18
+ def idiff
19
+ IntegrationDiff::Dsl.idiff
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module IntegrationDiff
2
+ class DummyRunner
3
+ def self.instance
4
+ @runner ||= DummyRunner.new
5
+ end
6
+
7
+ def start_run
8
+ end
9
+
10
+ def wrap_run
11
+ end
12
+
13
+ def screenshot(_)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,91 @@
1
+ require 'time'
2
+ require 'json'
3
+
4
+ module IntegrationDiff
5
+ class Runner
6
+ include Capybara::DSL
7
+
8
+ DIR = 'tmp/idff_images'
9
+
10
+ def self.instance
11
+ @runner ||= Runner.new(IntegrationDiff.base_uri,
12
+ IntegrationDiff.project_name,
13
+ IntegrationDiff.javascript_driver)
14
+ end
15
+
16
+ def initialize(base_uri, project_name, javascript_driver)
17
+ @base_uri = base_uri
18
+ @project_name = project_name
19
+ @javascript_driver = javascript_driver
20
+ Dir.mkdir(DIR) unless Dir.exist?(DIR)
21
+ end
22
+
23
+ # TODO: Improve error handling here for network timeouts
24
+ def start_run
25
+ @identifiers = []
26
+ draft_run
27
+ rescue StandardError => e
28
+ IntegrationDiff.logger.fatal e.message
29
+ raise e
30
+ end
31
+
32
+ # TODO: Improve error handling here for network timeouts
33
+ def wrap_run
34
+ @identifiers.each do |identifier|
35
+ upload_image(identifier)
36
+ end
37
+
38
+ finalize_run if @run_id
39
+ rescue StandardError => e
40
+ IntegrationDiff.logger.fatal e.message
41
+ raise e
42
+ end
43
+
44
+ def screenshot(identifier)
45
+ screenshot_name = image_file(identifier)
46
+ page.save_screenshot(screenshot_name, full: true)
47
+ @identifiers << identifier
48
+ end
49
+
50
+ private
51
+
52
+ def draft_run
53
+ run_name = @project_name + "-" + Time.now.iso8601
54
+
55
+ # will have to make it configurable. ie, read from env.
56
+ # https://github.com/code-mancers/integration-diff.rb/pull/4#discussion-diff-42290464
57
+ branch = `git rev-parse --abbrev-ref HEAD`.strip
58
+ author = `git config user.name`.strip
59
+ project = IntegrationDiff.project_name
60
+
61
+ response = connection.post('/api/v1/runs',
62
+ name: run_name, project: project, group: branch,
63
+ author: author, js_driver: @javascript_driver)
64
+
65
+ @run_id = JSON.parse(response.body)["id"]
66
+ end
67
+
68
+ def upload_image(identifier)
69
+ image_io = Faraday::UploadIO.new(image_file(identifier), 'image/png')
70
+ connection.post("/api/v1/runs/#{@run_id}/run_images",
71
+ identifier: identifier, image: image_io)
72
+ end
73
+
74
+ def finalize_run
75
+ connection.put("/api/v1/runs/#{@run_id}/status", status: "finalized")
76
+ end
77
+
78
+ def image_file(identifier)
79
+ "#{DIR}/#{identifier}.png"
80
+ end
81
+
82
+ def connection
83
+ @conn ||= Faraday.new(@base_uri) do |f|
84
+ f.request :basic_auth, IntegrationDiff.api_key, 'X'
85
+ f.request :multipart
86
+ f.request :url_encoded
87
+ f.adapter :net_http
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,3 @@
1
+ module IntegrationDiff
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,77 @@
1
+ require 'faraday'
2
+ require 'integration_diff/dummy_runner'
3
+ require 'integration_diff/runner'
4
+ require 'integration_diff/dsl'
5
+ require 'logger'
6
+
7
+ module IntegrationDiff
8
+ # configure domain to which all images have to be uploaded.
9
+ @@base_uri = "http://diff.codemancers.com"
10
+ def self.base_uri=(uri)
11
+ @@base_uri = uri
12
+ end
13
+ def self.base_uri
14
+ @@base_uri
15
+ end
16
+
17
+ # configure project name to which images belong to.
18
+ @@project_name = "idf"
19
+ def self.project_name=(name)
20
+ @@project_name = name
21
+ end
22
+ def self.project_name
23
+ @@project_name
24
+ end
25
+
26
+ # configure api_key required to authorize api access
27
+ @@api_key = ''
28
+ def self.api_key=(key)
29
+ @@api_key = key
30
+ end
31
+ def self.api_key
32
+ @@api_key
33
+ end
34
+
35
+ # configure js driver which is used for taking screenshots.
36
+ @@javascript_driver = "poltergeist"
37
+ def self.javascript_driver=(driver)
38
+ @@javascript_driver = driver
39
+ end
40
+ def self.javascript_driver
41
+ @@javascript_driver
42
+ end
43
+
44
+ # configure service to be mocked so that no screenshots are
45
+ # taken, and uploaded to service.
46
+ @@enable_service = false
47
+ def self.enable_service=(enable)
48
+ @@enable_service = enable
49
+ end
50
+ def self.enable_service
51
+ @@enable_service
52
+ end
53
+
54
+ # configure logger, which will be used to log issues if any
55
+ @@logger = Logger.new(STDOUT)
56
+ def self.logger=(new_logger)
57
+ @@logger = new_logger
58
+ end
59
+ def self.logger
60
+ @@logger
61
+ end
62
+
63
+ # helper to configure above variables.
64
+ def self.configure
65
+ yield(self)
66
+ end
67
+
68
+ # helps in setting up the run
69
+ def self.start_run
70
+ IntegrationDiff::Dsl.idiff.start_run
71
+ end
72
+
73
+ # helps in wrapping up run by uploading images
74
+ def self.wrap_run
75
+ IntegrationDiff::Dsl.idiff.wrap_run
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: integration-diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuva
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Rails integration for integration diff service
28
+ email:
29
+ - yuva@codemancers.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - Rakefile
36
+ - Readme.md
37
+ - lib/integration-diff.rb
38
+ - lib/integration_diff.rb
39
+ - lib/integration_diff/dsl.rb
40
+ - lib/integration_diff/dummy_runner.rb
41
+ - lib/integration_diff/runner.rb
42
+ - lib/integration_diff/version.rb
43
+ homepage: http://diff.codemancers.com
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.5.1
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Rails integration for integration diff service
67
+ test_files: []