capybara-differ 0.1.3 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f49afcd50987ff6406a109448e5919b0827644b
4
- data.tar.gz: 2423554dbd13a083579b11fd21ae065adf1a849b
3
+ metadata.gz: 3363d33f6de4c4f04aee3dc0ea0a689fe7647941
4
+ data.tar.gz: bcbf1a505d64b4fd991678c2f3c54a0948f5af55
5
5
  SHA512:
6
- metadata.gz: c473b4f4325262a56d38f6ed056e6cadece1374934f28a8cfd9f2a803a8c1f551f4a7692262c5c03ff94c1cee6ccd6651b58f6da1f0a14fa282419229374fde8
7
- data.tar.gz: cb7b5632c9cd5e3079e96ba79d6f9702d1ba41532b7d2caa573b84b2489cd8cba3dd4a963e5bfc564684eb44e13a383d6c2672d3cc60a10838856f4acc0ab759
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
 
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Differ
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -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
- diff = Diffy::Diff.new(old_beautified_html_path, new_beautified_html_path, diffy_options.merge(source: 'files'))
27
- diff.to_s(diffy_options.fetch(:format, :color))
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}.merge(@options.fetch(:diffy, {}))
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-differ
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuho Yamaguchi