Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Still Branch: Deprecated have_same_file_content_like and a_file_with_same_content_like matchers #557

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/aruba/matchers/deprecated.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Aruba.platform.require_matching_files('../deprecated/**/*.rb', __FILE__)
15 changes: 15 additions & 0 deletions lib/aruba/matchers/deprecated/file.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions lib/aruba/matchers/file/have_same_file_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <file1> has the same content like <file2>
#
# @param [String] file_name
Expand All @@ -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

Expand All @@ -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
82 changes: 82 additions & 0 deletions spec/aruba/matchers/deprecated_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
82 changes: 82 additions & 0 deletions spec/aruba/matchers/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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