Git Product home page Git Product logo

have_files's Introduction

have_files

A Crystal Spec/spec2 matcher for testing if two file trees are identical.

Build Status

Requirements

  • Git (git diff) - is used for file comparison.

Installation

Add this to your application's shard.yml:

dependencies:
  have_files:
    github: mosop/have_files

Usage

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

With spec2

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

API

have_files

Parameters

  • 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: /tmp)
  • cleanup : Determines whether working directory will be deleted after test ends. (default: true)

Details

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.

Releases

  • v0.3.0
    • (Breaking Change) nil can't be passed as an actual value any longer.
  • v0.2.0
    • (Experimental) spec2 matcher
    • (Breaking Change) Move HaveFiles::Expectation to HaveFiles::Spec::Expectation
    • (Breaking Change) Move HaveFiles::Dsl to HaveFiles::Spec::Dsl
  • v0.1.2
    • HaveFiles::Expectation
    • HaveFiles::Dsl

Development

[WIP]

Contributing

  1. Fork it ( https://github.com/mosop/have_files/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • mosop - creator, maintainer

have_files's People

Contributors

mosop avatar jkthorne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.