capybara-differ 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capybara-differ.gemspec +31 -0
- data/lib/capybara-differ.rb +66 -0
- data/lib/capybara-differ/version.rb +5 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a8bb2815f0d0de7e7f8ddea216f6a1bbac9059a
|
4
|
+
data.tar.gz: 7f959782fef98cca25a13be7fe89467538e621ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddd8d05d4c08a3c7881470b291a4ca68e27f08835e45bdb92c595852b51b49b3152fd6be1d1ea5e1cbac6bd40839e295424a388cf699207b79185347f7359af2
|
7
|
+
data.tar.gz: 05e759136e5b7324d93ba81c2b02649d172c8f060d6f0aeeef89a4b66a023bbd45139fb00d447580a69c6f1215cbe6fc2c3bbb4ff6e8d4228613a26d4f1fab64
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Kazuho Yamaguchi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Capybara::Differ
|
2
|
+
|
3
|
+
Print the diff of snapshots with Capybara.
|
4
|
+
This will help refactoring of views.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'capybara-differ'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install capybara-differ
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
In your system test(feature spec)
|
25
|
+
|
26
|
+
```
|
27
|
+
page.check_page('name_of_snapshot', selector: 'table')
|
28
|
+
```
|
29
|
+
|
30
|
+
You can get the diff from the history of `Capybara:Session#save_page`.
|
31
|
+
|
32
|
+
In this example(when you add class to table header),
|
33
|
+
you will see the diff of latest snapshot and the first snapshot in _tmp/capybara/name_of_snapshot/_ .
|
34
|
+
|
35
|
+
```
|
36
|
+
<th class="id">
|
37
|
+
ID
|
38
|
+
</th>
|
39
|
+
- <th class="name">
|
40
|
+
+ <th class="name foo">
|
41
|
+
Name
|
42
|
+
</th>
|
43
|
+
```
|
44
|
+
|
45
|
+
You can reset the target snapshot by removing files in _tmp/capybara/name_of_snapshot/_ .
|
46
|
+
Or remove the directory of snapshots.
|
47
|
+
|
48
|
+
## TODO
|
49
|
+
|
50
|
+
- Add an option to compare with the previous snapshot
|
51
|
+
- Add an option to suppress log
|
52
|
+
- Others
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kyamaguchi/capybara-differ.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capybara-differ"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "capybara-differ/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "capybara-differ"
|
7
|
+
spec.version = Capybara::Differ::VERSION
|
8
|
+
spec.authors = ["Kazuho Yamaguchi"]
|
9
|
+
spec.email = ["kzh.yap@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Snapshot pages and display diff to help refactoring.}
|
12
|
+
spec.description = %q{Snapshot pages and display diff to help refactoring.}
|
13
|
+
spec.homepage = "https://github.com/kyamaguchi/capybara-differ"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "capybara"
|
24
|
+
spec.add_dependency "selenium-webdriver"
|
25
|
+
spec.add_dependency "htmlbeautifier"
|
26
|
+
spec.add_dependency "diffy"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "byebug"
|
31
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
require 'htmlbeautifier'
|
3
|
+
require 'diffy'
|
4
|
+
require 'capybara'
|
5
|
+
require "capybara-differ/version"
|
6
|
+
|
7
|
+
module Capybara
|
8
|
+
module Differ
|
9
|
+
|
10
|
+
class Comparator
|
11
|
+
def initialize(old_file_path, new_file_path, options = {})
|
12
|
+
@old_file_path = old_file_path
|
13
|
+
@new_file_path = new_file_path
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def compare
|
18
|
+
if @old_file_path == @new_file_path
|
19
|
+
puts "There is no history of snapshots"
|
20
|
+
return ''
|
21
|
+
end
|
22
|
+
puts "Comparing two files#{target_selector ? ' with selector [' + target_selector + ']' : ''}\n #{@old_file_path}\n #{@new_file_path}"
|
23
|
+
old_html = beautified_html(@old_file_path)
|
24
|
+
new_html = beautified_html(@new_file_path)
|
25
|
+
Diffy::Diff.new(old_html, new_html, context: 2).to_s(:color)
|
26
|
+
end
|
27
|
+
|
28
|
+
def beautified_html(file)
|
29
|
+
raise ArgumentError, "#{file} not found" unless File.exist?(file)
|
30
|
+
doc = Nokogiri.HTML(File.read(file))
|
31
|
+
|
32
|
+
# Add line breaks to get diff by elements
|
33
|
+
doc.traverse do |x|
|
34
|
+
x.content = "\n#{x.content.strip}\n" if x.text?
|
35
|
+
end
|
36
|
+
|
37
|
+
html = target_selector ? doc.css(target_selector).to_html : doc.to_html
|
38
|
+
HtmlBeautifier.beautify(html)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def target_selector
|
44
|
+
@options.fetch(:selector, nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_page(name, options = {})
|
49
|
+
filename = File.join(name, Time.now.strftime('%Y%m%d%H%M%S') + '.html')
|
50
|
+
save_page(filename)
|
51
|
+
|
52
|
+
base_dir = File.join([Capybara.save_path, name].compact)
|
53
|
+
old_html_path = Dir[File.join(base_dir, '*')].first
|
54
|
+
new_html_path = Dir[File.join(base_dir, '*')].last
|
55
|
+
|
56
|
+
comparator = Capybara::Differ::Comparator.new(old_html_path, new_html_path, options)
|
57
|
+
if (result = comparator.compare).strip.size > 0
|
58
|
+
puts result
|
59
|
+
else
|
60
|
+
puts "No difference on '#{name}' snapshots"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Capybara::Session.send(:include, Capybara::Differ)
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-differ
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuho Yamaguchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: selenium-webdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: htmlbeautifier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: diffy
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Snapshot pages and display diff to help refactoring.
|
126
|
+
email:
|
127
|
+
- kzh.yap@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- capybara-differ.gemspec
|
142
|
+
- lib/capybara-differ.rb
|
143
|
+
- lib/capybara-differ/version.rb
|
144
|
+
homepage: https://github.com/kyamaguchi/capybara-differ
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.6.14
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: Snapshot pages and display diff to help refactoring.
|
168
|
+
test_files: []
|