Skip to content

Commit

Permalink
Merge pull request #819 from cucumber/improve-have-file-content-spec
Browse files Browse the repository at this point in the history
Fix specs for have_file_content matcher
  • Loading branch information
mvz authored Jun 19, 2021
2 parents 07a11b3 + 1780195 commit 3a4e9d0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions spec/aruba/matchers/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,30 @@
end

describe "failure messages" do
before do
Aruba.platform.write_file(@file_path, "aba")
end

def fail_with(message)
raise_error(RSpec::Expectations::ExpectationNotMetError, message)
end

example "for a string" do
expect do
expect(@file_name).to have_file_content("z")
end.to fail_with('expected "test.txt" to have file content: "z"')
end.to fail_with('expected "aba" to have file content: "z"')
end

example "for a regular expression" do
expect do
expect(@file_name).to have_file_content(/z/)
end.to fail_with('expected "test.txt" to have file content: /z/')
end.to fail_with('expected "aba" to have file content: /z/')
end

example "for a matcher" do
expect { expect(@file_name).to have_file_content(a_string_starting_with("z")) }
.to fail_with(
'expected "test.txt" to have file content: a string starting with "z"'
)
expect do
expect(@file_name).to have_file_content(a_string_starting_with("z"))
end.to fail_with 'expected "aba" to have file content: a string starting with "z"'
end
end
end
Expand Down

0 comments on commit 3a4e9d0

Please sign in to comment.