guard-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ script: "bundle exec rake spec"
data/Gemfile CHANGED
@@ -2,12 +2,18 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in guard-rails.gemspec
4
4
  gemspec
5
- gem 'rake', '0.8.7'
5
+ gem 'rake'
6
6
  gem 'fakefs', :require => nil
7
7
  gem 'guard'
8
8
  gem 'guard-rspec'
9
9
 
10
- # TODO: make this more OS-independent...like the rest of the gem
11
- gem 'growl'
12
- gem 'rb-fsevent'
10
+ require 'rbconfig'
11
+ if Config::CONFIG['target_os'] =~ /darwin/i
12
+ gem 'rb-fsevent', '>= 0.3.9'
13
+ gem 'growl', '~> 1.0.3'
14
+ end
15
+ if Config::CONFIG['target_os'] =~ /linux/i
16
+ gem 'rb-inotify', '>= 0.5.1'
17
+ gem 'libnotify', '~> 0.1.3'
18
+ end
13
19
 
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](http://travis-ci.org/johnbintz/guard-rails.png)](http://travis-ci.org/johnbintz/guard-rails)
2
+
1
3
  Want to restart your Rails development server whilst you work? Now you can!
2
4
 
3
5
  guard 'rails', :port => 5000 do
data/Rakefile CHANGED
@@ -1,24 +1,25 @@
1
+ include Rake::DSL if defined?(Rake::DSL)
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc 'Push everywhere!'
8
+ task :push_everywhere do
9
+ system %{git push origin master}
10
+ system %{git push guard master}
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
3
14
 
4
15
  namespace :spec do
5
16
  desc "Run on three Rubies"
6
17
  task :platforms do
7
- current = %x{rvm-prompt v}
8
-
9
- fail = false
10
- %w{1.8.7 1.9.2 ree}.each do |version|
11
- puts "Switching to #{version}"
12
- system %{rvm #{version}}
13
- system %{bundle exec rspec spec}
14
- if $?.exitstatus != 0
15
- fail = true
16
- break
17
- end
18
- end
19
-
20
- system %{rvm #{current}}
21
-
22
- exit (fail ? 1 : 0)
18
+ prefix = "rvm 1.8.7,1.9.2,ree ruby"
19
+ system %{#{prefix} bundle}
20
+ system %{#{prefix} bundle exec rake spec}
21
+ exit $?.exitstatus
23
22
  end
24
23
  end
24
+
25
+ task :default => 'spec:platforms'
@@ -12,7 +12,8 @@ module Guard
12
12
  :environment => 'development',
13
13
  :start_on_start => true,
14
14
  :force_run => false,
15
- :timeout => 20
15
+ :timeout => 20,
16
+ :server => nil
16
17
  }
17
18
 
18
19
  def initialize(watchers = [], options = {})
@@ -23,7 +24,8 @@ module Guard
23
24
  end
24
25
 
25
26
  def start
26
- UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{options[:environment]} environment."
27
+ server = options[:server] ? "#{options[:server]} and " : ""
28
+ UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
27
29
  run_all if options[:start_on_start]
28
30
  end
29
31
 
@@ -35,7 +37,7 @@ module Guard
35
37
  Notifier.notify("Rails restarted on port #{options[:port]}.", :title => "Rails restarted!", :image => :success)
36
38
  else
37
39
  UI.info "Rails NOT restarted, check your log files."
38
- Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failure)
40
+ Notifier.notify("Rails NOT restarted, check your log files.", :title => "Rails NOT restarted!", :image => :failed)
39
41
  end
40
42
  end
41
43
 
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Guard
2
4
  class RailsRunner
3
5
  MAX_WAIT_COUNT = 10
@@ -11,17 +13,14 @@ module Guard
11
13
  def start
12
14
  kill_unmanaged_pid! if options[:force_run]
13
15
  run_rails_command!
14
- count = 0
15
- while !has_pid? && count < MAX_WAIT_COUNT
16
- wait_for_pid_action
17
- count += 1
18
- end
19
- !(count == MAX_WAIT_COUNT)
16
+ wait_for_pid
20
17
  end
21
18
 
22
19
  def stop
23
20
  if File.file?(pid_file)
24
- system %{kill -INT #{File.read(pid_file).strip}}
21
+ system %{kill -KILL #{File.read(pid_file).strip}}
22
+ wait_for_no_pid if $?.exitstatus == 0
23
+ FileUtils.rm pid_file
25
24
  end
26
25
  end
27
26
 
@@ -38,6 +37,7 @@ module Guard
38
37
  ]
39
38
 
40
39
  rails_options << '-d' if options[:daemon]
40
+ rails_options << options[:server] if options[:server]
41
41
 
42
42
  %{sh -c 'cd #{Dir.pwd} && rails s #{rails_options.join(' ')} &'}
43
43
  end
@@ -69,20 +69,38 @@ module Guard
69
69
 
70
70
  def kill_unmanaged_pid!
71
71
  if pid = unmanaged_pid
72
- system %{kill -INT #{pid}}
72
+ system %{kill -KILL #{pid}}
73
+ FileUtils.rm pid_file
74
+ wait_for_no_pid
73
75
  end
74
76
  end
75
77
 
76
78
  def unmanaged_pid
77
- if RbConfig::CONFIG['host_os'] =~ /darwin/
78
- %x{lsof -P}.each_line { |line|
79
- if line["*:#{options[:port]} "]
80
- return line.split("\s")[1]
81
- end
82
- }
83
- end
79
+ %x{lsof -n -i TCP:#{options[:port]}}.each_line { |line|
80
+ if line["*:#{options[:port]} "]
81
+ return line.split("\s")[1]
82
+ end
83
+ }
84
84
  nil
85
85
  end
86
+
87
+ private
88
+ def wait_for_pid
89
+ wait_for_pid_loop
90
+ end
91
+
92
+ def wait_for_no_pid
93
+ wait_for_pid_loop(false)
94
+ end
95
+
96
+ def wait_for_pid_loop(check_for_existince = true)
97
+ count = 0
98
+ while !(check_for_existince ? has_pid? : !has_pid?) && count < MAX_WAIT_COUNT
99
+ wait_for_pid_action
100
+ count += 1
101
+ end
102
+ !(count == MAX_WAIT_COUNT)
103
+ end
86
104
  end
87
105
  end
88
106
 
@@ -1,4 +1,4 @@
1
1
  module GuardRails
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
4
4
 
@@ -46,6 +46,14 @@ describe Guard::RailsRunner do
46
46
  runner.build_rails_command.should match(%r{ -d})
47
47
  end
48
48
  end
49
+
50
+ context 'custom server' do
51
+ let(:options) { default_options.merge(:server => 'thin') }
52
+
53
+ it "should have the server name" do
54
+ runner.build_rails_command.should match(%r{thin})
55
+ end
56
+ end
49
57
  end
50
58
 
51
59
  describe '#start' do
@@ -41,7 +41,7 @@ describe Guard::Rails do
41
41
 
42
42
  before do
43
43
  Guard::UI.expects(:info).with('Restarting Rails...')
44
- Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), anything)
44
+ Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarting/), has_entry(:image => :pending))
45
45
  Guard::RailsRunner.any_instance.stubs(:pid).returns(pid)
46
46
  end
47
47
 
@@ -54,7 +54,7 @@ describe Guard::Rails do
54
54
 
55
55
  it "should restart and show the pid file" do
56
56
  Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
57
- Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), anything)
57
+ Guard::Notifier.expects(:notify).with(regexp_matches(/Rails restarted/), has_entry(:image => :success))
58
58
 
59
59
  guard.run_all
60
60
  end
@@ -68,7 +68,7 @@ describe Guard::Rails do
68
68
  it "should restart and show the pid file" do
69
69
  Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never
70
70
  Guard::UI.expects(:info).with(regexp_matches(/Rails NOT restarted/))
71
- Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), anything)
71
+ Guard::Notifier.expects(:notify).with(regexp_matches(/Rails NOT restarted/), has_entry(:image => :failed))
72
72
 
73
73
  guard.run_all
74
74
  end
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-rails
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease:
5
- version: 0.0.2
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
12
  authors:
8
13
  - John Bintz
@@ -10,41 +15,54 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-06-03 00:00:00 -04:00
18
+ date: 2011-08-04 00:00:00 -04:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: guard
23
+ prerelease: false
18
24
  requirement: &id001 !ruby/object:Gem::Requirement
19
25
  none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 19
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 2
23
34
  version: 0.2.2
24
35
  type: :runtime
25
- prerelease: false
26
36
  version_requirements: *id001
27
37
  - !ruby/object:Gem::Dependency
28
38
  name: rspec
39
+ prerelease: false
29
40
  requirement: &id002 !ruby/object:Gem::Requirement
30
41
  none: false
31
42
  requirements:
32
43
  - - ~>
33
44
  - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 2
48
+ - 6
49
+ - 0
34
50
  version: 2.6.0
35
51
  type: :development
36
- prerelease: false
37
52
  version_requirements: *id002
38
53
  - !ruby/object:Gem::Dependency
39
54
  name: mocha
55
+ prerelease: false
40
56
  requirement: &id003 !ruby/object:Gem::Requirement
41
57
  none: false
42
58
  requirements:
43
59
  - - ">="
44
60
  - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
45
64
  version: "0"
46
65
  type: :development
47
- prerelease: false
48
66
  version_requirements: *id003
49
67
  description: Restart Rails when things change in your app
50
68
  email:
@@ -57,6 +75,7 @@ extra_rdoc_files: []
57
75
 
58
76
  files:
59
77
  - .gitignore
78
+ - .travis.yml
60
79
  - Gemfile
61
80
  - Guardfile
62
81
  - README.md
@@ -84,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
103
  requirements:
85
104
  - - ">="
86
105
  - !ruby/object:Gem::Version
87
- hash: -1829971580643100829
106
+ hash: 3
88
107
  segments:
89
108
  - 0
90
109
  version: "0"
@@ -93,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
112
  requirements:
94
113
  - - ">="
95
114
  - !ruby/object:Gem::Version
96
- hash: -1829971580643100829
115
+ hash: 3
97
116
  segments:
98
117
  - 0
99
118
  version: "0"