-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class and example reloading #31
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97ca58c
Refactor error containment into its own class for resue
nilbus 56598bb
Syntax errors now stop the specs from running
nilbus c48a52f
Unload previous examples so that they do not accumulate
nilbus e500a3f
Use Rails 3.2+ class reloading when available
nilbus 74a7177
1.9 support for Containment
nilbus bf676e6
Unload previous examples before every test run
nilbus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,25 @@ | ||
module Guard | ||
class JRubyRSpec | ||
class Containment | ||
def initialize(options = {}) | ||
@error_handler = options.fetch(:error_handler, method(:output_as_guard_error)) | ||
end | ||
|
||
def protect | ||
yield | ||
rescue Exception => e | ||
error_handler.call e | ||
throw :task_has_failed | ||
end | ||
|
||
private | ||
|
||
attr_reader :error_handler | ||
|
||
def output_as_guard_error(exception) | ||
UI.error $!.message | ||
UI.error $!.backtrace.join "\n" | ||
end | ||
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,20 @@ | ||
class Reloaders | ||
def initialize | ||
@reloaders = [] | ||
end | ||
|
||
# Add a reloader to be called on reload | ||
def register(options = {}, &block) | ||
if options[:prepend] | ||
@reloaders.unshift block | ||
else | ||
@reloaders << block | ||
end | ||
end | ||
|
||
def reload(paths = []) | ||
@reloaders.each do |reloader| | ||
reloader.call(paths) | ||
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
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,29 @@ | ||
require 'spec_helper' | ||
require 'guard/jruby-rspec/containment' | ||
|
||
class Guard::JRubyRSpec | ||
describe Containment do | ||
subject(:containment) { described_class.new } | ||
|
||
describe '#protect' do | ||
it 'runs the block that is passed to it' do | ||
expect { |block| containment.protect &block }.to yield_control | ||
end | ||
|
||
it 'uses a default error_handler' do | ||
Guard::UI.should_receive(:error).at_least(1).times | ||
expect { containment.protect { raise 'busted' } }.to throw_symbol(:task_has_failed) | ||
end | ||
|
||
context 'with a custom error_handler' do | ||
subject(:containment) { described_class.new(:error_handler => lambda { @custom_handler_called = true }) } | ||
|
||
it 'calls the custom error_handler' do | ||
Guard::UI.should_receive(:error).never | ||
expect { containment.protect { raise 'busted' } }.to throw_symbol(:task_has_failed) | ||
@custom_handler_called.should be_true | ||
end | ||
end | ||
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,45 @@ | ||
require 'spec_helper' | ||
|
||
describe Reloaders do | ||
subject(:reloaders) { described_class.new } | ||
|
||
describe 'storing blocks to be executed at reload time' do | ||
it 'passes the paths to be reloaded to the reloaders' do | ||
reloaders.register do |paths| | ||
paths.should == ['/path/to/file'] | ||
end | ||
reloaders.reload ['/path/to/file'] | ||
end | ||
|
||
describe 'the order in which reloaders are executed' do | ||
before :each do | ||
@a = @b = @counter = 0 | ||
reloaders.register do | ||
@counter += 1 | ||
@a = @counter | ||
end | ||
reloaders.register(:prepend => prepend) do | ||
@counter += 1 | ||
@b = @counter | ||
end | ||
reloaders.reload | ||
end | ||
|
||
context 'in normal order' do | ||
let(:prepend) { false } | ||
it 'reloads in the same order as reloaders registered' do | ||
@a.should == 1 | ||
@b.should == 2 | ||
end | ||
end | ||
|
||
context 'with the 2nd reloader prepended' do | ||
let(:prepend) { true } | ||
it 'reloads in the same order as reloaders registered' do | ||
@a.should == 2 | ||
@b.should == 1 | ||
end | ||
end | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This spec failed for me, with
wrong number of arguments (1 for 0)
. But changing the lambda tolambda { |e| ...
fixed itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'll add a commit to fix that. I forgot that my JRuby was running in 1.8 mode. Thanks.