diff --git a/lib/aruba/matchers/deprecated.rb b/lib/aruba/matchers/deprecated.rb new file mode 100644 index 000000000..8c3dee00f --- /dev/null +++ b/lib/aruba/matchers/deprecated.rb @@ -0,0 +1 @@ +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..eb6f9132e --- /dev/null +++ b/lib/aruba/matchers/deprecated/file.rb @@ -0,0 +1,15 @@ +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 + + 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 +end \ 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..6f79889ba 100644 --- a/spec/aruba/matchers/deprecated_spec.rb +++ b/spec/aruba/matchers/deprecated_spec.rb @@ -36,4 +36,86 @@ 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 }.to raise_error RSpec::Expectations::ExpectationNotMetError + 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 }.to raise_error RSpec::Expectations::ExpectationNotMetError + end + end + end + end end diff --git a/spec/aruba/matchers/file_spec.rb b/spec/aruba/matchers/file_spec.rb index f417ea603..c76569f06 100644 --- a/spec/aruba/matchers/file_spec.rb +++ b/spec/aruba/matchers/file_spec.rb @@ -124,4 +124,86 @@ 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