-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup lib + spec structure; using guard
- Loading branch information
Showing
9 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "guard/localtunnel/version" | ||
|
||
module Guard | ||
module LocalTunnel | ||
# Your code goes here... | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/guard-localtunnel/version.rb → lib/guard/localtunnel/version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Guard | ||
module Localtunnel | ||
module LocalTunnel | ||
VERSION = "0.0.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |