Giter VIP home page Giter VIP logo

kicker's Introduction

Kicker

<img src=“https://travis-ci.org/alloy/kicker.svg?branch=master” alt=“Build Status” />

A lean, agnostic, flexible file-change watcher.

Installation

$ gem install kicker -s http://gemcutter.org

The short version

Usage: ./bin/kicker [options] [paths to watch]

  Available recipes: ignore, jstest, rails, ruby.

    -s, --silent                     Keep output to a minimum.
    -q, --quiet                      Quiet output. Don't print timestamps when logging.
    -c, --clear                      Clear console before each run.
    -l, --latency [FLOAT]            The time to collect file change events before acting on them. Defaults to 1 second.
    -r, --recipe [NAME]              A named recipe to load.
    -e, --execute [COMMAND]          The command to execute.
    -b, --ruby [PATH]                Use an alternate Ruby binary for spawned test runners. (Default is `ruby')

The long version

Execute a shell command

Show all files, whenever a change occurs in the current work directory:

$ kicker -e "ls -l" .

Show all files, whenever a change occurs to a specific file:

$ kicker -e "ls -l" foo.txt

Or use it as a ghetto-autotest, running tests whenever files change:

$ kicker -e "ruby test/test_case.rb" test/test_case.rb lib/file.rb

Et cetera.

Using recipes

A recipe is a predefined handler. You can use as many as you like, by specifying them with the --recipe (-r) option.

For instance, when in the root of a typical Ruby on Rails application, using the rails recipe will map models, concerns, controllers, helpers, and views to their respective test files. These will then all be ran with Ruby.

A few recipes come shipped with Kicker:

  • Typical Ruby library.

  • Ruby on Rails, as aforementioned.

  • JavaScript tests, to run it needs HeadlessSquirrel.

  • Ignore, ignores logs, tmp, and svn and git files.

Add your own shared recipes to ~/.kick folder or current working directory .kick.

Project specific handlers

Most of the time, you’ll want to create handlers specific to the project at hand. This can be done by adding your handlers to a .kick file and running Kicker from the directory containing it.

This file is reloaded once saved. No need to stop Kicker.

Writing handlers

Whenever file-change events occur, Kicker will go through a chain of handlers until that the files list is empty, or the end of the chain is reached.

Handlers are objects that respond to #call. These are typically Proc objects. (If you know Rack, you’re familiar with this concept.) Every handler gets passed a list of changed files and can decide whether or not to act on them. Normally when handling a file, you should remove it from the files list, unless you want to let the file fall through to another handler. In the same way, one can add files to handler to the files list.

Time for a simple example

process do |files|
  execute("rake docs:generate && open -a Safari html/index.html") if files.delete("README.rdoc")
end

A handler is defined by passing a block to process. Which is one of three possible callback chains to add your handlers to, the others being: pre_process and post_process. See Kernel for more info.

Then README.rdoc is deleted from the files array. If it did exist in the array and was deleted, a shell command is executed which runs a rake task to generate rdoc and open the docs with Safari.

Something more elaborate.

Consider a Rails application with a mailer. Since the naming convention of mailer views tend to be fairly application specific, a specific handler has to be added:

process do |files|
  test_files = files.take_and_map do |file|
    if path =~ %r{^app/views/mailer/\w+\.erb$}
      'test/unit/mailer_test.rb'

    # elsif ... handle more app specific stuff
    end
  end

  Ruby.run_tests test_files
end

The files list is iterated over with the Array#take_and_map method, which both removes and maps the results. This is an easy way to do a common thing in recipes. See Kicker::ArrayExt for details.

The handler then checks if the file is a mailer view and if so runs the mailers test case. Ruby.run_tests runs them with something like the following command:

execute "ruby -r #{test_files.join(' -r ')} -e ''" unless test_files.empty?

See Kernel for more info on the utility methods.

To load recipes from your ~/.kick file:

recipe :ignore
ignore(/^data\//)

That’s basically it, just remember that the order of specifying handlers can be important in your decision on where to specify handlers.

Notifiers

For platform specific notifications we use the notify gem. For supported backends see: github.com/jugyo/notify#feature.

You select the notify backend by setting the NOTIFY environment variable.

gem install terminal-notifier
env NOTIFY=terminal-notifier kicker

Contributors

  • Manfred Stienstra (@manfred)

  • Cristi Balan (@evilchelu)

  • Damir Zekic (@sidonath)

  • Adam Keys (@therealadam)

kicker's People

Contributors

alloy avatar cristibalan avatar iainbeeston avatar imajes avatar manfred avatar mikz avatar mvz avatar segiddins avatar sidonath avatar stepheneb avatar therealadam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kicker's Issues

need comparison with Guard

At first sight, my naive impression is that kicker reinvents the Guard wheel. There's nothing in the README.md to explain the differences between the two and the motivation for writing / using kicker over Guard. It would be very helpful if this information was documented.

Make using Kicker with (recipe) ext gems work.

E.g. I will make a kicker-xcodetest gem. (It will depend on another gem like xcodebuild-rb, which is why I don’t want it in kicker itself.)

  • Make sure that ext gems can add options to the CLI.
  • Should Kicker itself search for ‘kicker-’ ext gems and load them? (So that recipes show up everywhere?)

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Supress traceback on Ctrl-C

I've been using kicker to quickly run my tests for well over two years now. It's awesome, but I always slightly twitch a bit whenever I stop the kicking with Ctrl-C. Doing so prints a traceback, and tracebacks are to me the signal that something has gone wrong. In this case, nothing has gone wrong, I'm just stopping the application as I normally do.

My suggestion is to handle Ctrl-C (SIGINT, I guess) and just print a confirmation that kicker will now quit, rather than a lengthy thread traceback.

Very minor thing indeed, but a nice thing to fix nonetheless!
I would've fixed this myself, but my Ruby-fu was a bit too weak for this. I can't imagine it to be very tricky though.

Notifications on Linux?

@mvz In version 3 I’m dropping Growl support (on OS X) for the new User Notifications. Are notifications something that you would be interested in as well (on Linux)? If so, can you tell me which notification system is the current most accepted one?

WARNING: db:test:prepare is deprecated

I'm using kicker 3 with rails 4.1, but I'm seeing the following error whenever my schema file changes:

Kicker: rake db:test:prepare

WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.

I suspect the rails recipe is running db:test:prepare when the schema file changes.

Colors in output

I think some test runners try to detect where they're writing to and possibly don't include ANSI colors when running through Kicker cough rspec cough. The problem is that output coming from Kicker is all black, and I like my colors.

How to reproduce: kicker -r ruby in any directory with specs. Change a file.

Filename interpolation into repeated command

I run tests with kicker. I just realized that it would be very cool if kicker could pass the filename of the file that triggered the event into the command!

Imagine I run kicker -ce "hax0r_tests %s" and I save tests/test_lazerguns.py in my favorite $EDITOR. kicker would then execute hax0r_tests tests/test_lazerguns.py, in which the test runner will only run the tests in that file, making the feedback loop shorter and the developer happier!

Would this be possible to implement?

Possible startup bug

Just installed this and couldn't for the life of me get it to accept a command. I eventually tracked things down to find that this:

lib/kicker/validate.rb Line 10:
if process_chain.empty?

Changing that to
if process_chain.empty? && pre_process_chain.empty?

Seems to have fixed it peachy keen.

Minitest support

It would be nice if the default Ruby and Rails recipes supported minitest. This would mean testing for the inclusion of require 'minitest/autorun' in test_helper.rb or the existence of minitest_helper.rb and then using ruby to run the tests. I'm planning to implement this and submit a pull request.

Restart Rails application

Touch tmp/restart.txt, this assumes Passenger, if files like the following are modified:

  • config/environment.rb
  • config/environments/development.rb
  • config/initializers/*.rb

More?

Listen starts in polling mode

When updated my Gemfile.lock today I lost the rb-fsevent dependency from the lock file. Now when I start Kicker the Listen gem starts in polling mode.

Note that the rb-fsevent gem is still installed so theoretically it could still be loaded, I'm not sure if Bundler lets you load it though.

/Users/ejburns/Documents/kicker/lib/kicker.rb:102:in `mtime': Too many levels of symbolic links - /Users/ejburns/Documents/JavaEE/workareas/mojarra-adc/mojarra-1HEAD (Errno::ELOOP)

I have no symlinks in the picture. Here's the story:

uname -a
Darwin dhcp-adc-twvpn-1-vpnpool-10-154-26-196.vpn.oracle.com 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64

ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]

I just did a clone today.

Here's my ".kick" file:

process do |files|
r = ENV['ADC']
files.each do |src|
if ! src.include? ".svn"
dest = "#{r}/#{src}"
puts "Copying #{src} to #{dest}"
execute("cp #{src} #{dest}")
end
files.delete(src)
end
end

Here is my invocation script, which I call kicker:

export ADC="/net/adc2110030/scratch/ejburns/Documents/JavaEE/workareas/mojarra-1HEAD"

unzip $ADC/adc.zip

/Users/ejburns/Documents/kicker/bin/kicker /Users/ejburns/Documents/JavaEE/workareas/mojarra-adc

What I want to happen is that when I modify a file in mojarra-adc it gets copied to the same place in mojarra-1HEAD

Note that ADC is auto mounted. I can write to it successfully manually.

Kernel.execute override causing issues

I am using kicker in my rails project and now when I run database migrations, the "execute" method in ActiveRecord::Migration is getting overridden by the Kernel.execute definition in kicker. How can I avoid this?

Won't Start The Rails Recipe

I'm getting this error when trying to start the built-in rails recipe. Any ideas?

/Users/bryce/Sites/eventstart>kicker -r rails
/System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_import.rb:751:in `method_missing': undefined method `alias_method_chain' for String (NoMethodError)
    from /Users/bryce/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:9:in `included'
    from /Users/bryce/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:6:in `class_eval'
    from /Users/bryce/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string/output_safety.rb:6:in `included'
    from /Users/bryce/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string.rb:24:in `include'
    from /Users/bryce/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/string.rb:24
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
    from /Users/bryce/.gem/ruby/1.8/gems/kicker-2.2.2/lib/kicker/recipes/rails.rb:111
     ... 12 levels...
    from /Users/bryce/.gem/ruby/1.8/gems/kicker-2.2.2/lib/kicker.rb:13:in `run'
    from /Users/bryce/.gem/ruby/1.8/gems/kicker-2.2.2/bin/kicker:5
    from /Users/bryce/.gem/ruby/1.8/bin/kicker:19:in `load'
    from /Users/bryce/.gem/ruby/1.8/bin/kicker:19

Weird situation on syntax errors

When I run Kicker 3.0.0pre1 (on Mountain Lion, zsh) and I get a syntax error from either the test or an implementation file, something weird happens.

The output of the command is send to the terminal-notifier. Because it contains quotes the shell doesn't understand the command and prints an exception.

A solution would be to write the message to terminal-notifier through stdin instead of through an argument.

For an example see:

https://gist.github.com/2efd0e786f51e3a95f0b

Is activesupport a dependancy?

Full version information is ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.4].

When I try to run any kicker command, for example $ kicker

I get the following error:

/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': no such file to load -- active_support/core_ext/module (LoadError) from /Users/smebberson/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:inrequire'

Once I had a look at the source, I install the activesupport ruby gem and things started working...

Are you able to add it as a dependancy so that it automatically installs?

Kicker silently exits immediately after start

% kicker -r rails -b 'spin push'   
14:28:50.95 | Watching for changes on: /path/to/rails/app
14:28:50.95 | 
% 

When running kicker -r rails -b 'spin push', the program silently exits without an error (looks like a zero exit code).

I'm running ruby 2.0.0p195, kicker 2.6.1

No colours in notifier

I use kicker with the terminal-notifier gem, so that when each test run completes I get a native OS X notification of the result. Unfortunately, the notification text includes special characters for colouring the test output:

screen shot 2014-11-07 at 15 58 50

I'm not sure if this applies equally to all notifier gems, but should special characters like these be stripped before being sent to the notifier?

Superfluous output on 3.0.0-pre

When I run kicker on our Rails project (with the :rails recipe), I get a lot of excessive output.

17:18:54.59 | Executing: ruby -I. -r test/unit/magazine_test -e ''
Kicker: ruby -I. -r test/unit/magazine_test -e ''



....
4 specs, 0 failures, finished in 0.11 seconds.


17:18:55.99 | Success
Kicker: ....
4 specs, 0 failures, finished in 0.11 seconds.

For comparison, when I run the command myself, I get the following:

drutil% ruby -I. -r test/unit/magazine_test -e ''
....
4 specs, 0 failures, finished in 0.11 seconds.

Include note on the README that kicker doesn't work with non-system ruby?

I can't get it to work with my RVM installed ruby-1.8.7. Should it be working? (seems like no since I am getting a ruby-cocoa require failure)

/Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- osx/cocoa (LoadError)
        from /Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from /Users/timcharper/Developer/.rvm/gems/ruby-1.8.7-p334/gems/kicker-2.3.0/vendor/rucola/fsevents.rb:1
        from /Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from /Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from /Users/timcharper/Developer/.rvm/gems/ruby-1.8.7-p334/gems/kicker-2.3.0/lib/kicker.rb:2
        from /Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from /Users/timcharper/Developer/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from /Users/timcharper/Developer/.rvm/gems/ruby-1.8.7-p334/gems/kicker-2.3.0/bin/kicker:4
        from /Users/timcharper/Developer/.rvm/gems/ruby-1.8.7-p334/bin/kicker:19:in `load'
        from /Users/timcharper/Developer/.rvm/gems/ruby-1.8.7-p334/bin/kicker:19

lack of clarity around platform support

The github project description is "A lean, agnostic, flexible file-change watcher, using OS X FSEvents" but it seems from #23 that maybe this is no longer true. The README.md and description both need to eliminate any confusion about which platforms kicker runs on.

kicker -r rails just displays a usage message

Just installed kicker 2.2.0. When I run kicker -r rails, I just get the usage message. Likewise kicker -r rails . (both commands executing in a Rails directory, of course). Am I missing something about how to run the command, or is something else going wrong?

Bundler instead of Jeweler

Have you ever considered using Bundler instead of Jeweler? I just tried to set up a test environment to give you a patch and it was quite hard to know which gems are requested.

could kicker use fssm instead of rucola to work under ruby 1.9?

kicker depends on rucola which depends on RubyCocoa 0.13.2 which was last updated in 2008 and I don't think it works with Ruby 1.9.

Could kicker use fssm instead? https://github.com/ttilley/fssm

The File System State Monitor keeps track of the state of any
number of paths and will fire events when said state changes
(create/update/delete). FSSM supports using FSEvents on MacOS,
Inotify on GNU/Linux, and polling anywhere else.

The fssm spec tests pass on ruby 1.9.2:

[fssm-git (master)]$ rake spec
(in /Users/stephen/dev/ruby/src/gems/fssm-git)
/Users/stephen/.rvm/rubies/ruby-1.9.2-p180/bin/ruby -S bundle exec rspec --color --backtrace --format documentation ./spec/monitor_spec.rb ./spec/path_spec.rb
FSSM -> An optimized backend is available for this platform!
FSSM ->     gem install rb-fsevent

The File System State Monitor
  monitor
    with default options
      should call create callback upon file creation
      should call update callback upon file modification
      should call delete callback upon file deletion
      should call create and delete callbacks upon file renaming in the same directory
      should call create and delete callbacks upon file moving to another directory
      should not call callbacks upon directory operations
    when configured to consider files and directories
      should call create callback upon directory creation
      should call delete callback upon directory deletion
      should call create, update, and delete callbacks upon directory renaming in the same directory
      should call create, update, and delete callbacks upon directory moving to another directory
      should call create, update, and delete callbacks upon file renaming in the same directory
      should call create, update, and delete callbacks upon file moving to another directory
      should call delete callbacks upon directory structure deletion, in reverse order
      should call create callbacks upon directory structure creation, in order

The File System State Monitor
  paths
    should accept a valid filesystem directory
    should not accept an invalid filesystem directory
    should default the path to the current directory
    should accept an optional glob array parameter
    should accept an optional glob string parameter
    should accept an optional option parameter
    should default the glob to ['**/*']
    should accept a callback for update events
    should accept a callback for delete events
    should accept a callback for create events
    should accept a configuration block
    should pass file type to callbacks as the third argument if :directories option is used

Finished in 20.82 seconds
26 examples, 0 failures

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.