Giter VIP home page Giter VIP logo

guard-phpspec's Introduction

Guard::PHPSpec

guard-phpspec allows you to automatically run PHPSpec tests when sources are modified. It helps with integrating test-driven development (TDD) into your development process: Just launch guard-phpspec before you start working and it will notify you about the status of your tests!

Note: Although guard-phpspec should work with any PHP version PHPSpec supports, it has only been tested on PHP 5.3.8 and 5.4.4.

Meta

Install

Please be sure to have PHP, PHPSpec and Ruby installed on your machine before you proceed with the installation.

The latest versions of Ruby come with a packages-manager called gem. gem can be used to install various packages, including guard-phpspec.

To install guard-phpspec using gem, run the following command:

$ gem install guard-phpspec

but I suggest instead using Bundler/Gemfile when possible.

Update your Gemfile

group :test do
  gem 'guard'
  gem 'guard-phpspec', '1.0.*@dev'
gem

Then create/update the Guardfile to include PHPSpec watcher

run `guard init phpspec` or `bundle exec guard init phpspec`

This appends initialization of "guard-phpspec" to the Guardfile. You can manually update your Guardfile without guard init phpspec

  guard 'phpspec', :tests_path => 'spec', :cli => '--colors' do
    watch(%r{^.+Spec\.php$})
  end

Validate installation with Guard::PHPSpec's own specs

If you would like to run the specs guard-phpspec comes with:

cd `gem phpspec`
rspec spec
…

Usage

Just run guard or bundle exec guard in the in root working dir (where /specs dir is) Please read the Guard usage documentation.

Guardfile

guard-phpspec can be used with any kind of PHP projects that uses PHPSpec as its testing framwork. Please read the Guard documentation for more information about the Guardfile DSL.

By default, guard-phpspec will use the current working directory (pwd) to search for tests and run them on start (if you enabled the :all_on_start option).

Example PHP project

The [PHPSpec documentaion][4] uses the [Object Freezer][5] library as an example on how to organize tests. This project uses the Tests directory for its tests.

An example of the Guardfile for the same project would look something like:

guard 'phpspec', :tests_path => 'spec', :cli => '--colors' do
  # Watch tests files
  watch(%r{^.+_?[sS]pec\.php$})

  # Watch library files and run their tests
  watch(%r{^Object/(.+)\.php}) { |m| "Tests/#{m[1]}Spec.php" }
end

Options

The following options can be passed to Guard::PHPSpec:

      :all_on_start => false     # Run all tests on startup.
                                 # default: true

      :all_after_pass => false  # Run all tests after changed tests pass. This ensures
                                # that the process of making changed tests pass didn't
                                # break something else.
                                # default: true


      :keep_failed => false     # Remember failed tests and keep running them with
                                # each change until they pass.
                                # default: true


      :tests_path => 'tests'    # Relative path to the tests directory. This path
                                # is used when running all the tests.
                                # default: the current working directory (pwd)


      :cli => '--colors'        # The options passed to the phpunit command
                                # when running the tests.
                                # default: nil

Development

guard-phpspec's People

Contributors

lsd avatar

Stargazers

Roman avatar Michael Ludwig avatar

Watchers

 avatar fabrizio avatar James Cloos avatar

guard-phpspec's Issues

Missing template

Trying to create the initial Guardfile I get the following error:

 [email protected] : guard init phpspec                                                                                                                                                         10:03:51
10:04:03 - INFO - Writing new Guardfile to /Users/stu/Projects/api-consumers/kayako/Guardfile
/Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/plugin/base.rb:53:in `read': No such file or directory - /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-phpspec-0.0.2/lib/guard/phpspec/templates/Guardfile (Errno::ENOENT)
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/plugin/base.rb:53:in `template'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/plugin_util.rb:129:in `block in add_to_guardfile'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/plugin_util.rb:126:in `open'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/plugin_util.rb:126:in `add_to_guardfile'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/guardfile/generator.rb:62:in `initialize_template'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/guardfile.rb:30:in `initialize_template'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/cli.rb:176:in `block in init'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/cli.rb:175:in `each'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/lib/guard/cli.rb:175:in `init'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/gems/guard-2.6.0/bin/guard:6:in `<top (required)>'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/bin/guard:23:in `load'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/bin/guard:23:in `<main>'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
    from /Users/stu/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `<main>'

and indeed the directory it's looking for the template in does not exist.

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.