Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #110 from argent-smith/with_file_content

[FEATURE] Aruba::Api#with_file_content
  • Loading branch information...
commit 9c90100d4ebfdeb425e6b999798d0fc8c2e5d71c 2 parents 8f15079 + bb4a97a
Matt Wynne mattwynne authored
Showing with 42 additions and 2 deletions.
  1. +7 −0 lib/aruba/api.rb
  2. +35 −2 spec/aruba/api_spec.rb
7 lib/aruba/api.rb
View
@@ -94,6 +94,13 @@ def check_file_size(paths_and_sizes)
end
end
+ def with_file_content(file, &block)
+ prep_for_fs_check do
+ content = IO.read(file)
+ yield(content)
+ end
+ end
+
def check_file_content(file, partial_content, expect_match)
regexp = regexp(partial_content)
prep_for_fs_check do
37 spec/aruba/api_spec.rb
View
@@ -68,6 +68,39 @@ def announce_or_puts(*args)
end
end
end
-
end
-end
+
+ describe "#with_file_content" do
+ before :each do
+ @aruba.write_file(@file_name, "foo bar baz")
+ end
+
+ it "checks the given file's full content against the expectations in the passed block" do
+ @aruba.with_file_content @file_name do |full_content|
+ full_content.should == "foo bar baz"
+ end
+ end
+
+ context "checking the file's content against the expectations in the block" do
+ it "is successful when the inner expectations match" do
+ expect do
+ @aruba.with_file_content @file_name do |full_content|
+ full_content.should match /foo/
+ full_content.should_not match /zoo/
+ end
+ end . not_to raise_error RSpec::Expectations::ExpectationNotMetError
+ end
+
+ it "raises RSpec::Expectations::ExpectationNotMetError when the inner expectations don't match" do
+ expect do
+ @aruba.with_file_content @file_name do |full_content|
+ full_content.should match /zoo/
+ full_content.should_not match /foo/
+ end
+ end . to raise_error RSpec::Expectations::ExpectationNotMetError
+ end
+ end
+
+ end #with_file_content
+
+end # Aruba::Api
Please sign in to comment.
Something went wrong with that request. Please try again.