Permalink
Browse files

setup lib + spec structure; using guard

  • Loading branch information...
1 parent 0046624 commit 7e553270eb89b187d27d79de7ecd463e607c54b1 @drnic committed Apr 2, 2012
View
@@ -0,0 +1,13 @@
+# A sample Guardfile
+# More info at https://github.com/guard/guard#readme
+
+guard 'bundler' do
+ watch('Gemfile')
+ watch(/^.+\.gemspec/)
+end
+
+guard 'rspec', version: 2, cli: '--colour', focus: true, all_on_start: false, all_after_pass: false, keep_failed: false do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
View
@@ -2,8 +2,6 @@
Guard launches Local Tunnel on the port of the application's process (where also managed by Guard)
-* guard-puma - port 4000
-
## Installation
Add this line to your application's Gemfile:
View
@@ -1,2 +1,7 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
+require "rspec/core/rake_task"
+
+desc "Run all RSpec specs"
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
View
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/guard-localtunnel/version', __FILE__)
+require File.expand_path('../lib/guard/localtunnel/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Dr Nic Williams"]
@@ -13,5 +13,17 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "guard-localtunnel"
gem.require_paths = ["lib"]
- gem.version = Guard::Localtunnel::VERSION
+ gem.version = Guard::LocalTunnel::VERSION
+
+ gem.add_dependency "guard", ">= 1.0.1"
+ gem.add_dependency "localtunnel"
+ gem.add_development_dependency "rb-inotify"
+ gem.add_development_dependency "libnotify"
+ gem.add_development_dependency "rake", "~> 0.9.2.2"
+ gem.add_development_dependency "rspec", "~> 2.9.0"
+ gem.add_development_dependency "guard-rspec", "~> 0.7.0"
+ gem.add_development_dependency "bundler", "~> 1.1.0"
+ gem.add_development_dependency "guard-bundler"
+ gem.add_development_dependency "fakefs"
+ gem.add_development_dependency "mocha"
end
View
@@ -1,7 +0,0 @@
-require "guard-localtunnel/version"
-
-module Guard
- module Localtunnel
- # Your code goes here...
- end
-end
View
@@ -0,0 +1,7 @@
+require "guard/localtunnel/version"
+
+module Guard
+ module LocalTunnel
+ # Your code goes here...
+ end
+end
@@ -1,5 +1,5 @@
module Guard
- module Localtunnel
+ module LocalTunnel
VERSION = "0.0.1"
end
end
@@ -0,0 +1,92 @@
+require 'spec_helper'
+require 'guard/localtunnel'
+
+describe Guard::LocalTunnel do
+ let(:guard) { Guard::LocalTunnel.new(watchers, options) }
+ let(:watchers) { [] }
+ let(:options) { {} }
+
+ describe '#initialize' do
+ it "initializes with options" do
+ guard
+
+ guard.runner.options[:port].should == 4000
+ end
+ end
+
+ describe '#start' do
+ let(:ui_expectation) { Guard::UI.expects(:info).with(regexp_matches(/#{Guard::LocalTunnel::DEFAULT_OPTIONS[:port]}/)) }
+
+ context 'start on start' do
+ it "shows the right message and run startup" do
+ guard.expects(:reload).once
+ ui_expectation
+ guard.start
+ end
+ end
+
+ context 'no start on start' do
+ let(:options) { { :start_on_start => false } }
+
+ it "shows the right message and not run startup" do
+ guard.expects(:reload).never
+ ui_expectation
+ guard.start
+ end
+ end
+ end
+
+ describe '#reload' do
+ let(:pid) { '12345' }
+
+ before do
+ Guard::UI.expects(:info).with('Restarting LocalTunnel...')
+ Guard::Notifier.expects(:notify).with(regexp_matches(/LocalTunnel restarting/), has_entry(:image => :pending))
+ Guard::LocalTunnelRunner.any_instance.stubs(:pid).returns(pid)
+ end
+
+ let(:runner_stub) { Guard::LocalTunnelRunner.any_instance.stubs(:restart) }
+
+ context 'with pid file' do
+ before do
+ runner_stub.returns(true)
+ end
+
+ it "restarts and show the pid file" do
+ Guard::UI.expects(:info).with(regexp_matches(/#{pid}/))
+ Guard::Notifier.expects(:notify).with(regexp_matches(/LocalTunnel restarted/), has_entry(:image => :success))
+
+ guard.reload
+ end
+ end
+
+ context 'no pid file' do
+ before do
+ runner_stub.returns(false)
+ end
+
+ it "restarts and show the pid file" do
+ Guard::UI.expects(:info).with(regexp_matches(/#{pid}/)).never
+ Guard::UI.expects(:info).with(regexp_matches(/LocalTunnel NOT restarted/))
+ Guard::Notifier.expects(:notify).with(regexp_matches(/LocalTunnel NOT restarted/), has_entry(:image => :failed))
+
+ guard.reload
+ end
+ end
+ end
+
+ describe '#stop' do
+ it "stops correctly" do
+ Guard::Notifier.expects(:notify).with('Until next time...', anything)
+ guard.stop
+ end
+ end
+
+ describe '#run_on_change' do
+ it "reloads on change" do
+ guard.expects(:reload).once
+ guard.run_on_change([])
+ end
+ end
+end
+
View
@@ -0,0 +1,16 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+ENV["GUARD_ENV"] = 'test'
+require 'rspec'
+require 'mocha'
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+ config.mock_with :mocha
+end

0 comments on commit 7e55327

Please sign in to comment.