A Crystal Spec/spec2 matcher for testing if two file trees are identical.
- Git (git diff) - is used for file comparison.
Add this to your application's
dependencies: have_files: github: mosop/have_files
require "spec" require "have_files/spec" it "may work" do "/path/to/actual".should have_files "/path/to/expected" end
If test fails, have_files generates a diff message like:
Failures: 1) may work Failure/Error: nil.should have_files("/path/to/expected") do |dir| diff/test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diff/test.txt b/diff/test.txt index 8ab686e..415b41d 100644 --- a/diff/test.txt +++ b/diff/test.txt @@ -1 +1 @@ -Hello, World! +Hello, Worlb! # ./spec/hello_spec.cr:8 Finished in 203.09 milliseconds 1 examples, 1 failures, 0 errors, 0 pending
Preventing Namespace Pollution
To prevent pollution of top level namespace, you can directly create expectations.
require "spec" require "have_files/spec/expectation" it "may work" do "/path/to/actual".should HaveFiles::Spec::Expectation.new("/path/to/expected") end
Or you can define the
have_files method anywhere you like.
require "spec" require "have_files/spec/dsl" module Test extend HaveFiles::Spec::Dsl it "may work" do "/path/to/actual".should have_files "/path/to/expected" end end have_files "/path/to/expected" # => compile error
You can also use have_files with spec2.
require "spec2" require "have_files/spec2" Spec2.describe "with spec2" do it "is expected to work" do expect("/path/to/actual") have_files "/path/to/expected" end end
- expected_dir : A path to your expected file tree. (required)
- base_dir : A base path of working directory. To compare file trees with
git diff, have_files makes a working directory, that is temporary and uniquely named, under this path and copies all of target files into the working directory. (default:
- cleanup : Determines whether working directory will be deleted after test ends. (default:
have_files treats an actual value as a path of directory whose actual files. Then have_files copies the directory into a working directory and compares it to an expected file tree.
- (Breaking Change) nil can't be passed as an actual value any longer.
- (Experimental) spec2 matcher
- (Breaking Change) Move HaveFiles::Expectation to HaveFiles::Spec::Expectation
- (Breaking Change) Move HaveFiles::Dsl to HaveFiles::Spec::Dsl
- Fork it ( https://github.com/mosop/have_files/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
- mosop - creator, maintainer