capybara-differ 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/capybara-differ/version.rb +1 -1
- data/lib/capybara-differ.rb +14 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3363d33f6de4c4f04aee3dc0ea0a689fe7647941
|
4
|
+
data.tar.gz: bcbf1a505d64b4fd991678c2f3c54a0948f5af55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289633f65814632a6eb84ceba7598f7ea0b4965df65271d0f6be141a4b239f2a788a7be39bc00b72c2e88e3ee22f442073bda1f49bbf32d265a4c13dc6254819
|
7
|
+
data.tar.gz: e603cf24ae43d0e85dc45b6e23439c48d81c17fc000a372008d3ceb63f24cb15c2b0dbff492ced8342cc311bbf242e18ea5fc3ff03a32fd0beb00a6e43282647
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ This library try to remove the concerns on diff of whitespaces, linebreaks.
|
|
17
17
|
Expected use cases are
|
18
18
|
|
19
19
|
* Refactoring views of Rails app
|
20
|
-
* Migration of erb -> haml
|
20
|
+
* Migration of erb -> haml/slim
|
21
21
|
* Integration with [datagrid](https://github.com/bogdan/datagrid)
|
22
22
|
* Tracking sites
|
23
23
|
* visit -> save_page -> check_page
|
@@ -30,7 +30,7 @@ When you run the following commands periodically,
|
|
30
30
|
Capybara.save_path = 'tmp/capybara'
|
31
31
|
session = Capybara::Session.new(:selenium)
|
32
32
|
session.visit 'http://rubyonrails.org/'
|
33
|
-
session.check_page('rails_page')
|
33
|
+
session.check_page('rails_page', diffy: true)
|
34
34
|
```
|
35
35
|
|
36
36
|
you could get the following output.
|
@@ -69,8 +69,19 @@ Comparing two files
|
|
69
69
|
<section class="interior">
|
70
70
|
```
|
71
71
|
|
72
|
+
### git word diff
|
73
|
+
|
74
|
+
This library can display diff using git diff (default)
|
75
|
+
Check the output without diffy option
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
session.visit 'http://rubyonrails.org/'
|
79
|
+
session.check_page('rails_page')
|
80
|
+
```
|
81
|
+
|
72
82
|
### Dependencies
|
73
83
|
|
84
|
+
* git
|
74
85
|
* https://github.com/samg/diffy
|
75
86
|
* https://github.com/threedaymonk/htmlbeautifier
|
76
87
|
|
data/lib/capybara-differ.rb
CHANGED
@@ -20,11 +20,16 @@ module Capybara
|
|
20
20
|
return ''
|
21
21
|
end
|
22
22
|
puts "Comparing two files" + (target_selector ? " with selector [#{target_selector}]" : '')
|
23
|
-
puts " #{@old_file_path}\n #{@new_file_path}" unless diffy_options[:include_diff_info]
|
24
23
|
old_beautified_html_path = beautified_html(@old_file_path)
|
25
24
|
new_beautified_html_path = beautified_html(@new_file_path)
|
26
|
-
|
27
|
-
|
25
|
+
if use_diffy?
|
26
|
+
puts " #{@old_file_path}\n #{@new_file_path}" unless diffy_options[:include_diff_info]
|
27
|
+
diff = Diffy::Diff.new(old_beautified_html_path, new_beautified_html_path, diffy_options.merge(source: 'files'))
|
28
|
+
diff.to_s(diffy_options.fetch(:format, :color))
|
29
|
+
else
|
30
|
+
cmd = "git diff --no-index --color-words --word-diff-regex='\w+|[^[:space:]=\"<>]+' #{old_beautified_html_path} #{new_beautified_html_path}"
|
31
|
+
diff = Open3.popen3(cmd) { |i, o, e| o.read }
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
def beautified_html(file)
|
@@ -56,7 +61,12 @@ module Capybara
|
|
56
61
|
end
|
57
62
|
|
58
63
|
def diffy_options
|
59
|
-
{context: 2, include_diff_info: true}
|
64
|
+
opt = {context: 2, include_diff_info: true}
|
65
|
+
@options[:diffy].is_a?(Hash) ? opt.merge(@options[:diffy]) : opt
|
66
|
+
end
|
67
|
+
|
68
|
+
def use_diffy?
|
69
|
+
@options.has_key?(:diffy)
|
60
70
|
end
|
61
71
|
end
|
62
72
|
|