grosser / autotest

Save a file, autotest will run the matching tests! (Autotest without ZenTest)
121 stars 20 forks source link

How do I configure Autotest to run all tests whenever a file changes in either lib/ or spec/? #29

Closed Nerian closed 9 years ago

Nerian commented 13 years ago

I have a Sinatra app with the code inside lib/ and the tests inside spec/.

How do I configure Autotest to run all tests whenever a file changes in either lib/ or spec/?

grosser commented 13 years ago

Should be the default behavior, did you try with --style rspec / --style rspec2 ?

Nerian commented 13 years ago

I have two spec files inside spec/.

When I do changes inside user_spec nothing happens.

When I do changes in login_spec the tests inside that file get executed.

.autotest

require "autotest/bundler"
require 'autotest/growl'
require 'autotest/fsevent'
require "autotest/restart"

Autotest::Growl::one_notification_per_run = true
Autotest::Growl::remote_notification = true

Autotest.add_hook :initialize do |autotest|
  %w{.git .DS_Store tmp log}.each do |exception|
    autotest.add_exception(exception)
  end
end

# Override autotest default magic to rerun all tests every time a
# change is detected on the file system.
class Autotest

  def get_to_green
    begin
      rerun_all_tests
      wait_for_changes unless all_good
    end until all_good
  end

end

login_spec.rb

require_relative '../spec_helper'

describe "Login" do
  describe "A user" do
    describe "should be able to log in" do
      it "and then see the home page" do
        pending()
        visit('/')
        within("#menu") do
          page.should have_content('Nottion')
        end        
      end
    end
  end
end

user_spec.rb

require_relative '../spec_helper'

describe "As an User" do
  describe "when I access the home page" do
    describe "if am not authenticated" do
      it "I should not see the home page" do
        pending()
        visit '/'
        page.should_not have_selector('#menu')
      end

      it "I should be redirected to the login page" do
        pending()
        visit '/'        
      end
    end
  end
end

Output:

davinci git:(master) ✗ bundle exec autotest --style rspec2
loading autotest/rspec2

--------------------------------------------------------------------------------

bundle exec /Users/Nerian/.rvm/rubies/ruby-1.9.3-rc1/bin/ruby -S /Users/Nerian/.rvm/gems/ruby-1.9.3-rc1@davinci/gems/rspec-core-2.6.4/bin/rspec --tty '/Users/Nerian/Projects/davinci/spec/acceptance/user_spec.rb'
**

Pending:
  As an User when I access the home page if am not authenticated I should not see the home page
    # No reason given
    # ./spec/acceptance/user_spec.rb:6
  As an User when I access the home page if am not authenticated I should be redirected to the login page
    # No reason given
    # ./spec/acceptance/user_spec.rb:12

Finished in 0.00084 seconds
2 examples, 0 failures, 2 pending
grosser commented 13 years ago

no idea :<

Nerian commented 13 years ago

I removed this from .autotest and everything worked as expected :)

Autotest.add_hook :initialize do |autotest|
  %w{.git .DS_Store tmp log}.each do |exception|
    autotest.add_exception(exception)
  end
end

I don't understand why that causes any problem, though.

grosser commented 13 years ago

seems like the matchin is roken, can you pinpoint it to any of %w{.git .DS_Store tmp log} ?

Nerian commented 13 years ago

Seems that log is the troublemaker

grosser commented 13 years ago

thats kind of weird... are you brave enough to go poke in the code, so this gets fixed for good ? :)