Skip to content

Commit

Permalink
Merge pull request #555 from xtrasimplicity/Feature/RenameHaveSameFil…
Browse files Browse the repository at this point in the history
…eContentLikeMatcher

Renamed `#have_same_file_content_like` matcher
  • Loading branch information
xtrasimplicity authored Apr 1, 2018
2 parents d027542 + 395b2b4 commit 53741ea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG][2].
* Make forgetting setup_aruba a hard failure ([#510] by [mvz])
* Improve documentation for users and developers ([#454], [#456], [#457], [#460],
[#459], [#461], [#475], [#494] by [olleolleolle], [maxmeyer], [mvz])
* Removed `have_same_file_content_like` and `a_file_with_same_content_like` matchers, in favour of `have_same_file_content_as` and `a_file_with_same_content_as`. ([#555](https://github.com/cucumber/aruba/pull/555) by [XtraSimplicity](https://github.com/xtrasimplicity))

### Removed

Expand Down
4 changes: 2 additions & 2 deletions lib/aruba/cucumber/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@

Then(/^(?:a|the) file(?: named)? "([^"]*)" should (not )?be equal to file "([^"]*)"/) do |file, negated, reference_file|
if negated
expect(file).not_to have_same_file_content_like(reference_file)
expect(file).not_to have_same_file_content_as(reference_file)
else
expect(file).to have_same_file_content_like(reference_file)
expect(file).to have_same_file_content_as(reference_file)
end
end

Expand Down
11 changes: 5 additions & 6 deletions lib/aruba/matchers/file/have_same_file_content.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'rspec/expectations/version'

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 +18,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 @@ -43,4 +42,4 @@
end
end

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
53 changes: 48 additions & 5 deletions spec/aruba/matchers/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def fail_with(message)
end
end

describe "to have_same_file_content_like" do
describe "to have_same_file_content_as" do
let(:file_name) { @file_name }
let(:file_path) { @file_path }

Expand All @@ -120,12 +120,12 @@ def fail_with(message)
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 }
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_like reference_file }
expect { expect(file_name).not_to have_same_file_content_as reference_file }
.to raise_error RSpec::Expectations::ExpectationNotMetError
end
end
Expand All @@ -135,17 +135,60 @@ def fail_with(message)
let(:reference_file_content) { 'bar' }

context 'and this is expected' do
it { expect(file_name).not_to have_same_file_content_like reference_file }
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_like reference_file }
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


describe 'to_have_file_size' do
context 'when file exists' do
Expand Down

0 comments on commit 53741ea

Please sign in to comment.