From 6076fbaa10dbc0dd7070216359efa0c9d3a9d674 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 17:20:00 +1100 Subject: [PATCH 1/6] Deprecated `have_same_file_content_like` and `a_file_with_same_content_like`. --- lib/aruba/matchers/deprecated.rb | 15 ++++ .../matchers/file/have_same_file_content.rb | 10 +-- spec/aruba/matchers/deprecated_spec.rb | 84 +++++++++++++++++++ spec/aruba/matchers/file_spec.rb | 84 +++++++++++++++++++ 4 files changed, 188 insertions(+), 5 deletions(-) create mode 100644 lib/aruba/matchers/deprecated.rb diff --git a/lib/aruba/matchers/deprecated.rb b/lib/aruba/matchers/deprecated.rb new file mode 100644 index 000000000..b9dee803e --- /dev/null +++ b/lib/aruba/matchers/deprecated.rb @@ -0,0 +1,15 @@ +module DeprecatedMatchers + def have_same_file_content_like(expected) + RSpec.deprecate('`have_same_file_content_like`', replacement: '`have_same_file_content_as`') + + have_same_file_content_as(expected) + end + + def a_file_with_same_content_like(expected) + RSpec.deprecate('`a_file_with_same_content_like`', replacement: '`a_file_with_same_content_as`') + + a_file_with_same_content_as(expected) + end +end + +RSpec::Matchers.send(:include, DeprecatedMatchers) \ No newline at end of file diff --git a/lib/aruba/matchers/file/have_same_file_content.rb b/lib/aruba/matchers/file/have_same_file_content.rb index c59c799b5..30922cf62 100644 --- a/lib/aruba/matchers/file/have_same_file_content.rb +++ b/lib/aruba/matchers/file/have_same_file_content.rb @@ -2,7 +2,7 @@ require 'fileutils' -# @!method have_same_file_content_like(file_name) +# @!method have_same_file_content_as(file_name) # This matchers checks if has the same content like # # @param [String] file_name @@ -19,10 +19,10 @@ # @example Use matcher # # RSpec.describe do -# it { expect(file1).to have_same_file_content_like(file2) } -# it { expect(files).to include a_file_with_same_content_like(file2) } +# it { expect(file1).to have_same_file_content_as(file2) } +# it { expect(files).to include a_file_with_same_content_as(file2) } # end -RSpec::Matchers.define :have_same_file_content_like do |expected| +RSpec::Matchers.define :have_same_file_content_as do |expected| match do |actual| stop_all_commands @@ -44,5 +44,5 @@ end if RSpec::Expectations::Version::STRING >= '3.0' - RSpec::Matchers.alias_matcher :a_file_with_same_content_like, :have_same_file_content_like + RSpec::Matchers.alias_matcher :a_file_with_same_content_as, :have_same_file_content_as end diff --git a/spec/aruba/matchers/deprecated_spec.rb b/spec/aruba/matchers/deprecated_spec.rb index b0228f898..b04f33a8b 100644 --- a/spec/aruba/matchers/deprecated_spec.rb +++ b/spec/aruba/matchers/deprecated_spec.rb @@ -36,4 +36,88 @@ end end end + + describe "to have_same_file_content_like" do + let(:file_name) { @file_name } + let(:file_path) { @file_path } + + let(:reference_file) { 'fixture' } + + before :each do + @aruba.write_file(@file_name, "foo bar baz") + @aruba.write_file(reference_file, reference_file_content) + end + + context 'when files are the same' do + let(:reference_file_content) { 'foo bar baz' } + + context 'and this is expected' do + it { expect(file_name).to have_same_file_content_like reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(file_name).not_to have_same_file_content_like reference_file } + .to raise_error RSpec::Expectations::ExpectationNotMetError + end + end + end + + context 'when files are not the same' do + let(:reference_file_content) { 'bar' } + + context 'and this is expected' do + it { expect(file_name).not_to have_same_file_content_like reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(file_name).to have_same_file_content_like reference_file } + .to raise_error RSpec::Expectations::ExpectationNotMetError + end + end + end + end + + describe "include a_file_with_same_content_like" do + let(:reference_file) { 'fixture' } + let(:reference_file_content) { 'foo bar baz' } + let(:file_with_same_content) { 'file_a.txt' } + let(:file_with_different_content) { 'file_b.txt' } + + before :each do + @aruba.write_file(file_with_same_content, reference_file_content) + @aruba.write_file(reference_file, reference_file_content) + @aruba.write_file(file_with_different_content, 'Some different content here...') + end + + context 'when the array of files includes a file with the same content' do + let(:files) { [file_with_different_content, file_with_same_content] } + + context 'and this is expected' do + it { expect(files).to include a_file_with_same_content_like reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(files).not_to include a_file_with_same_content_like reference_file } + end + end + + end + + context 'when the array of files does not include a file with the same content' do + let(:files) { [file_with_different_content] } + + context 'and this is expected' do + it { expect(files).not_to include a_file_with_same_content_like reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(files).to include a_file_with_same_content_like reference_file } + end + end + end + end end diff --git a/spec/aruba/matchers/file_spec.rb b/spec/aruba/matchers/file_spec.rb index f417ea603..2a3fe6a62 100644 --- a/spec/aruba/matchers/file_spec.rb +++ b/spec/aruba/matchers/file_spec.rb @@ -124,4 +124,88 @@ def fail_with(message) it { expect(@file_name).not_to have_file_size(0) } end end + + describe "to have_same_file_content_as" do + let(:file_name) { @file_name } + let(:file_path) { @file_path } + + let(:reference_file) { 'fixture' } + + before :each do + @aruba.write_file(@file_name, "foo bar baz") + @aruba.write_file(reference_file, reference_file_content) + end + + context 'when files are the same' do + let(:reference_file_content) { 'foo bar baz' } + + context 'and this is expected' do + it { expect(file_name).to have_same_file_content_as reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(file_name).not_to have_same_file_content_as reference_file } + .to raise_error RSpec::Expectations::ExpectationNotMetError + end + end + end + + context 'when files are not the same' do + let(:reference_file_content) { 'bar' } + + context 'and this is expected' do + it { expect(file_name).not_to have_same_file_content_as reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(file_name).to have_same_file_content_as reference_file } + .to raise_error RSpec::Expectations::ExpectationNotMetError + end + end + end + end + + describe "include a_file_with_same_content_as" do + let(:reference_file) { 'fixture' } + let(:reference_file_content) { 'foo bar baz' } + let(:file_with_same_content) { 'file_a.txt' } + let(:file_with_different_content) { 'file_b.txt' } + + before :each do + @aruba.write_file(file_with_same_content, reference_file_content) + @aruba.write_file(reference_file, reference_file_content) + @aruba.write_file(file_with_different_content, 'Some different content here...') + end + + context 'when the array of files includes a file with the same content' do + let(:files) { [file_with_different_content, file_with_same_content] } + + context 'and this is expected' do + it { expect(files).to include a_file_with_same_content_as reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(files).not_to include a_file_with_same_content_as reference_file } + end + end + + end + + context 'when the array of files does not include a file with the same content' do + let(:files) { [file_with_different_content] } + + context 'and this is expected' do + it { expect(files).not_to include a_file_with_same_content_as reference_file } + end + + context 'and this is not expected' do + it do + expect { expect(files).to include a_file_with_same_content_as reference_file } + end + end + end + end end From 041de416a5013c594f7cf5540d1b9b4cc51ce219 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 18:29:39 +1100 Subject: [PATCH 2/6] Refactored a little. --- lib/aruba/matchers/deprecated.rb | 16 +--------------- lib/aruba/matchers/deprecated/file.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 lib/aruba/matchers/deprecated/file.rb diff --git a/lib/aruba/matchers/deprecated.rb b/lib/aruba/matchers/deprecated.rb index b9dee803e..8c3dee00f 100644 --- a/lib/aruba/matchers/deprecated.rb +++ b/lib/aruba/matchers/deprecated.rb @@ -1,15 +1 @@ -module DeprecatedMatchers - def have_same_file_content_like(expected) - RSpec.deprecate('`have_same_file_content_like`', replacement: '`have_same_file_content_as`') - - have_same_file_content_as(expected) - end - - def a_file_with_same_content_like(expected) - RSpec.deprecate('`a_file_with_same_content_like`', replacement: '`a_file_with_same_content_as`') - - a_file_with_same_content_as(expected) - end -end - -RSpec::Matchers.send(:include, DeprecatedMatchers) \ No newline at end of file +Aruba.platform.require_matching_files('../deprecated/**/*.rb', __FILE__) diff --git a/lib/aruba/matchers/deprecated/file.rb b/lib/aruba/matchers/deprecated/file.rb new file mode 100644 index 000000000..7232d8ecb --- /dev/null +++ b/lib/aruba/matchers/deprecated/file.rb @@ -0,0 +1,11 @@ +def have_same_file_content_like(expected) + RSpec.deprecate('`have_same_file_content_like`', :replacement => '`have_same_file_content_as`') + + have_same_file_content_as(expected) +end + +def a_file_with_same_content_like(expected) + RSpec.deprecate('`a_file_with_same_content_like`', :replacement => '`a_file_with_same_content_as`') + + a_file_with_same_content_as(expected) +end \ No newline at end of file From c1e552c056b0d3f0fd6dff36ba2062477c9c4044 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 18:32:42 +1100 Subject: [PATCH 3/6] Fixing specs. --- spec/aruba/matchers/deprecated_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/aruba/matchers/deprecated_spec.rb b/spec/aruba/matchers/deprecated_spec.rb index b04f33a8b..302c1c59b 100644 --- a/spec/aruba/matchers/deprecated_spec.rb +++ b/spec/aruba/matchers/deprecated_spec.rb @@ -57,8 +57,7 @@ context 'and this is not expected' do it do - expect { expect(file_name).not_to have_same_file_content_like reference_file } - .to raise_error RSpec::Expectations::ExpectationNotMetError + expect { expect(file_name).not_to have_same_file_content_like reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end end @@ -72,8 +71,7 @@ context 'and this is not expected' do it do - expect { expect(file_name).to have_same_file_content_like reference_file } - .to raise_error RSpec::Expectations::ExpectationNotMetError + expect { expect(file_name).to have_same_file_content_like reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end end From 8641bf56d526858b13e1124decda6879f41b7fbf Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 18:35:03 +1100 Subject: [PATCH 4/6] Fixing specs in CI. --- spec/aruba/matchers/file_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/aruba/matchers/file_spec.rb b/spec/aruba/matchers/file_spec.rb index 2a3fe6a62..c76569f06 100644 --- a/spec/aruba/matchers/file_spec.rb +++ b/spec/aruba/matchers/file_spec.rb @@ -145,8 +145,7 @@ def fail_with(message) context 'and this is not expected' do it do - expect { expect(file_name).not_to have_same_file_content_as reference_file } - .to raise_error RSpec::Expectations::ExpectationNotMetError + expect { expect(file_name).not_to have_same_file_content_as reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end end @@ -160,8 +159,7 @@ def fail_with(message) context 'and this is not expected' do it do - expect { expect(file_name).to have_same_file_content_as reference_file } - .to raise_error RSpec::Expectations::ExpectationNotMetError + expect { expect(file_name).to have_same_file_content_as reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end end From aec74f7d9047420f3297354895b404d8a5f95b52 Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 19:01:26 +1100 Subject: [PATCH 5/6] Refactored a little. --- lib/aruba/matchers/deprecated/file.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/aruba/matchers/deprecated/file.rb b/lib/aruba/matchers/deprecated/file.rb index 7232d8ecb..eb6f9132e 100644 --- a/lib/aruba/matchers/deprecated/file.rb +++ b/lib/aruba/matchers/deprecated/file.rb @@ -1,11 +1,15 @@ -def have_same_file_content_like(expected) - RSpec.deprecate('`have_same_file_content_like`', :replacement => '`have_same_file_content_as`') +module RSpec + module Matchers + def have_same_file_content_like(expected) + RSpec.deprecate('`have_same_file_content_like`', :replacement => '`have_same_file_content_as`') - have_same_file_content_as(expected) -end + have_same_file_content_as(expected) + end -def a_file_with_same_content_like(expected) - RSpec.deprecate('`a_file_with_same_content_like`', :replacement => '`a_file_with_same_content_as`') + def a_file_with_same_content_like(expected) + RSpec.deprecate('`a_file_with_same_content_like`', :replacement => '`a_file_with_same_content_as`') - a_file_with_same_content_as(expected) + a_file_with_same_content_as(expected) + end + end end \ No newline at end of file From d4f58d1e322e6f3fe3e656794d9cc8592549d09d Mon Sep 17 00:00:00 2001 From: Andrew Walter Date: Sun, 25 Mar 2018 20:05:34 +1100 Subject: [PATCH 6/6] Fixing incomplete specs. --- spec/aruba/matchers/deprecated_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/aruba/matchers/deprecated_spec.rb b/spec/aruba/matchers/deprecated_spec.rb index 302c1c59b..6f79889ba 100644 --- a/spec/aruba/matchers/deprecated_spec.rb +++ b/spec/aruba/matchers/deprecated_spec.rb @@ -98,7 +98,7 @@ context 'and this is not expected' do it do - expect { expect(files).not_to include a_file_with_same_content_like reference_file } + expect { expect(files).not_to include a_file_with_same_content_like reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end @@ -113,7 +113,7 @@ context 'and this is not expected' do it do - expect { expect(files).to include a_file_with_same_content_like reference_file } + expect { expect(files).to include a_file_with_same_content_like reference_file }.to raise_error RSpec::Expectations::ExpectationNotMetError end end end