Class: CLIntegracon::Diff
- Inherits:
-
Object
- Object
- CLIntegracon::Diff
- Includes:
- Enumerable
- Defined in:
- lib/CLIntegracon/diff.rb
Instance Attribute Summary collapse
-
#expected ⇒ Pathname
readonly
The expected file.
-
#preparator ⇒ Proc<(Pathname)->(to_s)
] the proc, which transforms the files in a better comparable form.
-
#produced ⇒ Pathname
readonly
The produced file.
-
#relative_path ⇒ Pathname
readonly
The relative path to the expected file.
Instance Method Summary collapse
-
#each(options = {}, &block) ⇒ Diffy::Diff
Enumerate all lines which differ.
-
#initialize(expected, produced, relative_path = nil, &preparator) ⇒ Diff
constructor
Init a new diff.
-
#is_equal? ⇒ Bool
Check if the produced output equals the expected.
- #prepared_expected ⇒ Object
- #prepared_produced ⇒ Object
Constructor Details
#initialize(expected, produced, relative_path = nil, &preparator) ⇒ Diff
Init a new diff
39 40 41 42 43 44 45 |
# File 'lib/CLIntegracon/diff.rb', line 39 def initialize(expected, produced, relative_path=nil, &preparator) @expected = expected @produced = produced @relative_path = relative_path preparator ||= Proc.new { |x| x } #id self.preparator = preparator end |
Instance Attribute Details
#expected ⇒ Pathname (readonly)
Returns the expected file.
11 12 13 |
# File 'lib/CLIntegracon/diff.rb', line 11 def expected @expected end |
#preparator ⇒ Proc<(Pathname)->(to_s)
Returns ] the proc, which transforms the files in a better comparable form.
23 24 25 |
# File 'lib/CLIntegracon/diff.rb', line 23 def preparator @preparator end |
#produced ⇒ Pathname (readonly)
Returns the produced file.
15 16 17 |
# File 'lib/CLIntegracon/diff.rb', line 15 def produced @produced end |
#relative_path ⇒ Pathname (readonly)
Returns the relative path to the expected file.
19 20 21 |
# File 'lib/CLIntegracon/diff.rb', line 19 def relative_path @relative_path end |
Instance Method Details
#each(options = {}, &block) ⇒ Diffy::Diff
Enumerate all lines which differ.
75 76 77 78 |
# File 'lib/CLIntegracon/diff.rb', line 75 def each( = {}, &block) = { :source => 'files', :context => 3 }.merge Diffy::Diff.new(prepared_expected.to_s, prepared_produced.to_s, ).each &block end |
#is_equal? ⇒ Bool
Check if the produced output equals the expected
60 61 62 63 64 65 66 |
# File 'lib/CLIntegracon/diff.rb', line 60 def is_equal? @is_equal ||= if prepared_expected.is_a? Pathname FileUtils.compare_file(prepared_expected, prepared_produced) else prepared_expected == prepared_produced end end |
#prepared_expected ⇒ Object
47 48 49 |
# File 'lib/CLIntegracon/diff.rb', line 47 def prepared_expected @prepared_expected ||= preparator.call(expected) end |
#prepared_produced ⇒ Object
51 52 53 |
# File 'lib/CLIntegracon/diff.rb', line 51 def prepared_produced @prepared_produced ||= preparator.call(produced) end |