spackle 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +166 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/ruby-project-root +14 -0
- data/bin/spackle +14 -0
- data/bin/spackle-vim-load-quickfix +47 -0
- data/bin/spackle-vim-open +49 -0
- data/lib/spackle/commandline.rb +53 -0
- data/lib/spackle/configuration.rb +37 -0
- data/lib/spackle/error.rb +31 -0
- data/lib/spackle/helpers/ruby_project_root.rb +34 -0
- data/lib/spackle/output/base.rb +44 -0
- data/lib/spackle/output/vim_quickfix.rb +7 -0
- data/lib/spackle/output.rb +2 -0
- data/lib/spackle/spec/base_formatter.rb +22 -0
- data/lib/spackle/spec/spackle_formatter.rb +14 -0
- data/lib/spackle/spec.rb +1 -0
- data/lib/spackle.rb +104 -0
- data/spec/integration_spec.rb +84 -0
- data/spec/spackle/commandline_spec.rb +48 -0
- data/spec/spackle/configuration_spec.rb +43 -0
- data/spec/spackle/error_spec.rb +34 -0
- data/spec/spackle/output/base_spec.rb +53 -0
- data/spec/spackle/output/vim_quickfix_spec.rb +25 -0
- data/spec/spackle/spec/base_formatter_spec.rb +15 -0
- data/spec/spackle/spec/spackle_formatter_spec.rb +58 -0
- data/spec/spackle_error_fixture.rb +10 -0
- data/spec/spackle_spec.rb +203 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/test_app_helper.rb +55 -0
- data/support/vim/spackle.vim +17 -0
- data/test_app/lib/error_raiser.rb +7 -0
- data/test_app/lib/method_typo.rb +7 -0
- data/test_app/lib/missing_end.rb +7 -0
- data/test_app/lib/working_class.rb +7 -0
- data/test_app/spec/error_raiser_spec.rb +14 -0
- data/test_app/spec/failing_working_class_spec.rb +14 -0
- data/test_app/spec/method_typo_spec.rb +14 -0
- data/test_app/spec/missing_end_spec.rb +13 -0
- data/test_app/spec/passing_working_class_spec.rb +14 -0
- data/test_app/spec/spec_helper.rb +8 -0
- metadata +127 -0
data/lib/spackle.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require 'spackle/configuration'
|
4
|
+
require 'spackle/error'
|
5
|
+
require 'spackle/output'
|
6
|
+
require 'spackle/spec' if defined? Spec
|
7
|
+
require 'spackle/helpers/ruby_project_root'
|
8
|
+
|
9
|
+
module Spackle
|
10
|
+
class << self
|
11
|
+
def already_initialized?
|
12
|
+
@already_initialized == true
|
13
|
+
end
|
14
|
+
|
15
|
+
def callback_command
|
16
|
+
Spackle.configuration.callback_command
|
17
|
+
end
|
18
|
+
|
19
|
+
def configuration
|
20
|
+
@configuration ||= Spackle::Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure
|
24
|
+
yield configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def error_formatter_class
|
28
|
+
class_name = configuration.error_formatter.to_s.
|
29
|
+
split("_").collect { |w| w.capitalize }.join
|
30
|
+
begin
|
31
|
+
eval("Spackle::Output::#{class_name}")
|
32
|
+
rescue SyntaxError
|
33
|
+
raise RuntimeError.new("Spackle Error: no configuration for error_formatter_class -- have you configured Spackle with a .spackle file?")
|
34
|
+
rescue NameError
|
35
|
+
raise RuntimeError.new("Spackle Error: Cannot find Spackle::Output::#{class_name} -- have you configured Spackle with a .spackle file?")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def init(options = {})
|
40
|
+
return if already_initialized?
|
41
|
+
|
42
|
+
@already_initialized = true
|
43
|
+
load_config
|
44
|
+
File.unlink(spackle_file) if File.exists?(spackle_file)
|
45
|
+
|
46
|
+
case options[:with]
|
47
|
+
when :spec_formatter
|
48
|
+
::Spec::Runner.options.parse_format "Spackle::Spec::SpackleFormatter:/dev/null"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def load_config
|
53
|
+
load_config_from_dotfile
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_config_from_dotfile
|
57
|
+
config_files = []
|
58
|
+
|
59
|
+
if ENV['SPACKLE_CONFIG']
|
60
|
+
# SPACKLE_CONFIG is mostly intended for use with the integration tests
|
61
|
+
config_files << File.expand_path(ENV['SPACKLE_CONFIG'])
|
62
|
+
else
|
63
|
+
config_files << File.expand_path("~/.spackle")
|
64
|
+
|
65
|
+
project_root = Spackle::Helpers::RubyProjectRoot.search Dir.pwd
|
66
|
+
if project_root
|
67
|
+
config_files << File.join(project_root, ".spackle")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
config_files.inject(false) do |config_loaded, file|
|
72
|
+
if File.exists? file
|
73
|
+
load file
|
74
|
+
config_loaded = true
|
75
|
+
end
|
76
|
+
config_loaded
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def spackle_file
|
81
|
+
projectname = Spackle::Helpers::RubyProjectRoot.search Dir.pwd
|
82
|
+
projectname = File.basename(projectname) + ".spackle" if projectname
|
83
|
+
filename = configuration.spackle_file || projectname || "default.spackle"
|
84
|
+
|
85
|
+
File.join(tempdir, filename)
|
86
|
+
end
|
87
|
+
|
88
|
+
def tempdir
|
89
|
+
configuration.tempdir || '/tmp'
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_finished(errors)
|
93
|
+
return unless configuration.error_formatter
|
94
|
+
File.open( spackle_file, "w", 0600 ) do |f|
|
95
|
+
errors.each do |error|
|
96
|
+
f.write error_formatter_class.format(error)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
system(configuration.callback_command, spackle_file) if configuration.callback_command
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
# This matcher is necessary because the expected/actual strings look just
|
4
|
+
# like bits of regular Ruby backtraces, which apparently is how autotest
|
5
|
+
# figures out which files to test. Outputting bits of the backtraces from
|
6
|
+
# the testapp's test harness mightily confuses an autotest running Spackle.
|
7
|
+
Spec::Matchers.define :have_spackle do |expected|
|
8
|
+
match do |actual|
|
9
|
+
actual.spackle_output == expected
|
10
|
+
end
|
11
|
+
|
12
|
+
def sanitize(str)
|
13
|
+
str.gsub(/_spec.rb/, '_s_p_e_c_dot_r_b')
|
14
|
+
end
|
15
|
+
|
16
|
+
failure_message_for_should do |actual|
|
17
|
+
<<-EOF
|
18
|
+
Expected spackles to match, but they didn't! Note that the "expected"
|
19
|
+
and "got" below have been transformed so autotest doesn't get confused
|
20
|
+
and blow up. See spec/integration_spec.rb for details.
|
21
|
+
COMMAND
|
22
|
+
#{actual.command}
|
23
|
+
EXPECTED:
|
24
|
+
#{sanitize expected }
|
25
|
+
GOT:
|
26
|
+
#{sanitize actual.spackle_output}
|
27
|
+
EOF
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
if ENV['INTEGRATE_SPACKLE']
|
33
|
+
|
34
|
+
# -- expected spackles ---------------------------------------------------
|
35
|
+
FAILING_WORKING_CLASS = <<EOF
|
36
|
+
./spec/failing_working_class_spec.rb:9: expected false, got true
|
37
|
+
EOF
|
38
|
+
|
39
|
+
ERROR_RAISER = <<EOF
|
40
|
+
./spec/error_raiser_spec.rb:9: an unhandled error
|
41
|
+
EOF
|
42
|
+
|
43
|
+
MISSING_END = <<EOF
|
44
|
+
EOF
|
45
|
+
|
46
|
+
METHOD_TYPO = <<EOF
|
47
|
+
./spec/method_typo_spec.rb:9: undefined method `sirt' for [3, 1, 2]:Array
|
48
|
+
EOF
|
49
|
+
# ------------------------------------------------------------------------
|
50
|
+
|
51
|
+
DOT_SPACKLE = '/tmp/dot_spackle'
|
52
|
+
|
53
|
+
describe "integration" do
|
54
|
+
before do
|
55
|
+
@harness = TestAppHelper::Spec.new
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
it "running passing_working_class should return no output" do
|
60
|
+
@harness.run(:passing_working_class)
|
61
|
+
@harness.spackle_output.should be_empty
|
62
|
+
end
|
63
|
+
|
64
|
+
it "running failing_working_class should return a spackle" do
|
65
|
+
@harness.run(:failing_working_class)
|
66
|
+
@harness.should have_spackle(FAILING_WORKING_CLASS)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "running error_raiser should return a spackle" do
|
70
|
+
@harness.run(:error_raiser)
|
71
|
+
@harness.should have_spackle(ERROR_RAISER)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "running missing_end should return a spackle" do
|
75
|
+
@harness.run(:missing_end)
|
76
|
+
@harness.spackle_output.should be_empty
|
77
|
+
end
|
78
|
+
|
79
|
+
it "running method_typo should return a spackle" do
|
80
|
+
@harness.run(:method_typo)
|
81
|
+
@harness.should have_spackle(METHOD_TYPO)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
require 'spackle/commandline'
|
4
|
+
module Spackle
|
5
|
+
describe Commandline do
|
6
|
+
describe "--install option" do
|
7
|
+
before do
|
8
|
+
Commandline.stub! :show_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should call install with the argument" do
|
12
|
+
Commandline.should_receive(:install).with("foo")
|
13
|
+
result = Commandline.parse(%w(--install foo))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return 1 and output an error if the argument is unrecognized" do
|
17
|
+
lambda {
|
18
|
+
Commandline.parse(%w(--install foo)).should == 1
|
19
|
+
}.should raise_error(RuntimeError, /unrecognized/i)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "for vim" do
|
23
|
+
it "should copy the plugin" do
|
24
|
+
Commandline.should_receive(:puts)
|
25
|
+
FileUtils.should_receive(:copy).with(/spackle.vim$/, /plugin$/)
|
26
|
+
Commandline.parse %w(--install vim)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise an error if the destination dir doesn't exist" do
|
30
|
+
File.stub! :directory? => false
|
31
|
+
lambda {
|
32
|
+
Commandline.parse %w(--install vim)
|
33
|
+
}.should raise_error(RuntimeError, /directory/)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise an error if it receives unrecognized options" do
|
38
|
+
lambda {
|
39
|
+
Commandline.parse %w(something unexpected)
|
40
|
+
}.should raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
module Spackle
|
4
|
+
describe Configuration do
|
5
|
+
before do
|
6
|
+
@subject = Spackle::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it { should respond_to(:callback_command=) }
|
10
|
+
it { should respond_to(:callback_command) }
|
11
|
+
it { should respond_to(:tempdir=) }
|
12
|
+
it { should respond_to(:tempdir) }
|
13
|
+
it { should respond_to(:error_formatter=) }
|
14
|
+
it { should respond_to(:error_formatter) }
|
15
|
+
it { should respond_to(:spackle_file=) }
|
16
|
+
it { should respond_to(:spackle_file) }
|
17
|
+
|
18
|
+
it { should respond_to(:set_defaults_for) }
|
19
|
+
|
20
|
+
it "should raise an error if defaults_for receives an unrecognized argument" do
|
21
|
+
lambda {
|
22
|
+
@subject.set_defaults_for :something_invalid
|
23
|
+
}.should raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "defaults for vim" do
|
27
|
+
before do
|
28
|
+
@subject.set_defaults_for :vim
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set the editor to spackle-vim-load-quickfix" do
|
32
|
+
@subject.callback_command.should == "spackle-vim-load-quickfix"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the error formatter to :vim_quickfix" do
|
36
|
+
@subject.error_formatter.should == :vim_quickfix
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
module Spackle
|
4
|
+
describe Error do
|
5
|
+
before do
|
6
|
+
@subject = Error.new("message")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should store the message" do
|
10
|
+
@subject.message.should == "message"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have an empty backtrace" do
|
14
|
+
@subject.backtrace.should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow adding errors by file and line" do
|
18
|
+
file = "foo/bar/baz.rb"
|
19
|
+
line = 123
|
20
|
+
@subject.add_error file, line
|
21
|
+
@subject.backtrace.should have(1).errors
|
22
|
+
@subject.backtrace.first.file.should == file
|
23
|
+
@subject.backtrace.first.line.should == line
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow adding errors using a block" do
|
27
|
+
@subject = Error.new("message") do |e|
|
28
|
+
e.add_error "foo/bar", 12
|
29
|
+
e.add_error "bubba/flubba", 23
|
30
|
+
end
|
31
|
+
@subject.backtrace.should have(2).errors
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
module Spackle::Output
|
4
|
+
describe Base do
|
5
|
+
before do
|
6
|
+
@error = spackle_error_fixture
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "instance" do
|
10
|
+
before do
|
11
|
+
@subject = Base.new spackle_error_fixture
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should call format_backtrace_line" do
|
15
|
+
line_count = spackle_error_fixture.backtrace.size
|
16
|
+
@subject.should_receive(:format_backtrace_line).exactly(line_count).times
|
17
|
+
@subject.format
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return the formatted output" do
|
21
|
+
@subject.stub!(:format_backtrace_line).and_return("foo")
|
22
|
+
@subject.format.should == "foo\n" * 3
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "instantiating" do
|
27
|
+
it "should use Spackle's default error if none specified" do
|
28
|
+
Spackle.should_receive(:current_error).and_return(@error)
|
29
|
+
Base.new.error.should == @error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#format class method" do
|
34
|
+
before do
|
35
|
+
@instance = mock("instance")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should initialize and return formatted lines" do
|
39
|
+
Base.should_receive(:new).with(@error).and_return(@instance)
|
40
|
+
@instance.should_receive :format
|
41
|
+
Base.format @error
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should use Spackle's default error if none specified" do
|
45
|
+
Base.should_receive(:new).with(@error).and_return(@instance)
|
46
|
+
Spackle.should_receive(:current_error).and_return(@error)
|
47
|
+
@instance.stub!(:format)
|
48
|
+
Base.format
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
module Spackle::Output
|
4
|
+
describe VimQuickfix do
|
5
|
+
before do
|
6
|
+
Spackle.stub!(:current_error)
|
7
|
+
end
|
8
|
+
it "should format errors in 'path:line: message' format" do
|
9
|
+
VimQuickfix.new.format_backtrace_line("message", "file", "123").should == "file:123: message"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should strip newlines from messages" do
|
13
|
+
VimQuickfix.new.format_backtrace_line("many\nlines", "ignore", "ignore").should_not match(/\n/)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should integrate with Base and return a nice quickfix!" do
|
17
|
+
VimQuickfix.format( spackle_error_fixture ).should == <<-EOF
|
18
|
+
/clutzy/child/waving/arms:1: CATASTROPHE: the milk was spilled! Begin crying? [Y/n]
|
19
|
+
/cupboard/shelf/glass:350: CATASTROPHE: the milk was spilled! Begin crying? [Y/n]
|
20
|
+
/fridge/shelf/jug/milk:4: CATASTROPHE: the milk was spilled! Begin crying? [Y/n]
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
2
|
+
|
3
|
+
module Spackle::Spec
|
4
|
+
describe BaseFormatter do
|
5
|
+
it "should initialize errors to an empty array" do
|
6
|
+
BaseFormatter.new(nil,nil).errors.should == []
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should notify Spackle of the finished test along with the errors on close" do
|
10
|
+
Spackle.should_receive(:test_finished).with([])
|
11
|
+
BaseFormatter.new(nil,nil).close
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
|
2
|
+
|
3
|
+
module Spackle::Spec
|
4
|
+
describe SpackleFormatter do
|
5
|
+
before do
|
6
|
+
@output = StringIO.new
|
7
|
+
@subject = SpackleFormatter.new({}, @output)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "example_failed" do
|
11
|
+
before do
|
12
|
+
@error = mock("error", :add_error => nil)
|
13
|
+
Spackle::Error.stub!(:new).and_return @error
|
14
|
+
|
15
|
+
Spackle.stub!(:format_error)
|
16
|
+
|
17
|
+
@exception = mock "exception", {
|
18
|
+
:message => "a message",
|
19
|
+
:backtrace => [
|
20
|
+
"some/path/to/file:123",
|
21
|
+
"another/path/to/file:345"
|
22
|
+
]
|
23
|
+
}
|
24
|
+
@failure = mock "failure", { :exception => @exception }
|
25
|
+
end
|
26
|
+
|
27
|
+
def example_failed
|
28
|
+
@subject.example_failed("example", "counter", @failure)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create an error with the message" do
|
32
|
+
Spackle::Error.should_receive(:new).with("a message").and_return(@error)
|
33
|
+
example_failed
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should add two entries to the error" do
|
37
|
+
@error.should_receive(:add_error).exactly(2).times
|
38
|
+
example_failed
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should add errors by file and line number" do
|
42
|
+
@error.should_receive(:add_error) do |file, line|
|
43
|
+
correct_args =
|
44
|
+
(file == "some/path/to/file" && line = "123") ||
|
45
|
+
(file == "another/path/to/file" && line = "345")
|
46
|
+
correct_args.should be_true
|
47
|
+
end
|
48
|
+
example_failed
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should append the to the errors format" do
|
52
|
+
example_failed
|
53
|
+
@subject.errors.last.should == @error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SpackleErrorFixture
|
2
|
+
def spackle_error_fixture
|
3
|
+
Spackle::Error.new "CATASTROPHE: the milk was spilled! Begin crying? [Y/n]" do |e|
|
4
|
+
e.add_error "/clutzy/child/waving/arms", 1
|
5
|
+
e.add_error "/cupboard/shelf/glass", 350
|
6
|
+
e.add_error "/fridge/shelf/jug/milk", 4
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class Spackle::Output::SomeClass
|
4
|
+
def self.format(*args)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
describe Spackle do
|
10
|
+
it "should be configurable" do
|
11
|
+
config = Spackle.configuration
|
12
|
+
config.should == Spackle.configuration
|
13
|
+
Spackle.configure do |c|
|
14
|
+
c.should == config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "load_config_from_dotfile" do
|
19
|
+
before do
|
20
|
+
Spackle.stub!(:load)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return false if a config file was found" do
|
24
|
+
File.stub(:exists?).and_return false
|
25
|
+
Spackle.load_config_from_dotfile.should be_false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true if a config file was found" do
|
29
|
+
File.stub(:exists?).and_return true
|
30
|
+
Spackle.load_config_from_dotfile.should be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should check for a .spackle file in the project root directory" do
|
34
|
+
Spackle::Helpers::RubyProjectRoot.should_receive(:search).and_return("/some/dir/project")
|
35
|
+
File.should_receive(:exists?).with any_args()
|
36
|
+
File.should_receive(:exists?).with("/some/dir/project/.spackle").and_return(true)
|
37
|
+
Spackle.load_config_from_dotfile.should be_true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
describe "loading configuration" do
|
43
|
+
it "should have nil for the callback command if no config found" do
|
44
|
+
Spackle.stub(:load_config_from_dotfile).and_return(false)
|
45
|
+
Spackle.load_config
|
46
|
+
Spackle.configuration.callback_command.should be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not use the vim defaults when a config file is found" do
|
50
|
+
Spackle.configuration.should_not_receive(:set_defaults_for).with(:vim)
|
51
|
+
Spackle.stub(:load_config_from_dotfile).and_return(true)
|
52
|
+
Spackle.load_config
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
describe "tempdir" do
|
58
|
+
it "should default to /tmp" do
|
59
|
+
Spackle.tempdir.should == "/tmp"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should use the configured tempdir" do
|
63
|
+
Spackle.configuration.tempdir = "my_tempdir"
|
64
|
+
Spackle.tempdir.should == "my_tempdir"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "spackle_file" do
|
69
|
+
it "should return the tempdir" do
|
70
|
+
Spackle.stub!(:tempdir).and_return("/temp")
|
71
|
+
Spackle.spackle_file.should match(%r{^/temp/.+})
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should end with the Configuration's spackle_file if specified" do
|
75
|
+
Spackle.configuration.spackle_file = "my_spackle"
|
76
|
+
Spackle.spackle_file.should match(%r(/my_spackle$))
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "when no configured spackle_file" do
|
80
|
+
before do
|
81
|
+
Spackle.configuration.spackle_file = nil
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should end with default.spackle if no project root detected" do
|
85
|
+
Spackle::Helpers::RubyProjectRoot.stub! :search => nil
|
86
|
+
Spackle.spackle_file.should match(%r(/default\.spackle$))
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be named after the project root if detected" do
|
90
|
+
Spackle::Helpers::RubyProjectRoot.should_receive(:search).and_return("/some/dir/project")
|
91
|
+
Spackle.spackle_file.should match(%r(/project\.spackle$))
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "formatter_class" do
|
99
|
+
it "should convert the configuration's error_formatter to a class" do
|
100
|
+
Spackle.configuration.error_formatter = :some_class
|
101
|
+
Spackle.error_formatter_class.should == Spackle::Output::SomeClass
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should raise a helpful error if no matching class can be found" do
|
105
|
+
Spackle.configuration.error_formatter = :not_existing
|
106
|
+
lambda {
|
107
|
+
Spackle.error_formatter_class
|
108
|
+
}.should raise_error(RuntimeError, /\.spackle/)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "test_finished" do
|
113
|
+
before do
|
114
|
+
@errors = [ spackle_error_fixture ]
|
115
|
+
@formatter = mock("formatter", :format => "string")
|
116
|
+
@file = StringIO.new
|
117
|
+
File.stub!(:open).and_yield(@file)
|
118
|
+
Spackle.stub!(
|
119
|
+
:error_formatter_class => @formatter,
|
120
|
+
:system => true,
|
121
|
+
:spackle_file => @spackle_file
|
122
|
+
)
|
123
|
+
Spackle.configuration.error_formatter = :something
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should write the output to the spackle_file if defined" do
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not write the spackle_file if the error_formatter is undefined" do
|
130
|
+
Spackle.configuration.error_formatter = nil
|
131
|
+
File.should_not_receive(:open)
|
132
|
+
Spackle.test_finished @errors
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should invoke the callback_command if defined" do
|
136
|
+
Spackle.configuration.callback_command = '/bin/true'
|
137
|
+
Spackle.should_receive(:system).with('/bin/true', @spackle_file)
|
138
|
+
Spackle.test_finished @errors
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should not invoke the callback_command if none defined" do
|
142
|
+
Spackle.configuration.callback_command = nil
|
143
|
+
Spackle.should_not_receive(:system)
|
144
|
+
Spackle.test_finished @errors
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should format the errors" do
|
148
|
+
@formatter.should_receive(:format).with(@errors[0])
|
149
|
+
Spackle.test_finished @errors
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should write formatted output to file" do
|
153
|
+
@file.should_receive(:write).with("string")
|
154
|
+
Spackle.test_finished @errors
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "init" do
|
159
|
+
before do
|
160
|
+
Spackle.stub! :load_config => true,
|
161
|
+
:spackle_file => true,
|
162
|
+
:already_initialized? => false
|
163
|
+
File.stub! :unlink => true,
|
164
|
+
:exists? => false
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should only init once" do
|
168
|
+
Spackle.should_receive(:load_config).exactly(1).times
|
169
|
+
Spackle.init
|
170
|
+
Spackle.stub! :already_initialized? => true
|
171
|
+
Spackle.should_not_receive(:load_config)
|
172
|
+
Spackle.init
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should delete the old file, if it exists" do
|
176
|
+
Spackle.stub! :spackle_file => "file"
|
177
|
+
File.should_receive(:exists?).with("file").and_return(true)
|
178
|
+
File.should_receive(:unlink).with("file")
|
179
|
+
Spackle.init
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should not delete the old file unless it exists" do
|
183
|
+
Spackle.stub! :spackle_file => "file"
|
184
|
+
File.should_receive(:exists?).with("file").and_return(false)
|
185
|
+
File.should_not_receive(:unlink).with("file")
|
186
|
+
Spackle.init
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should load the config" do
|
190
|
+
Spackle.should_receive :load_config
|
191
|
+
Spackle.init
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should insert the RSpec formatter if :with => :spec_formatter specified" do
|
195
|
+
Spec::Runner.options.should_receive(:parse_format).with /Spackle::Spec::SpackleFormatter/
|
196
|
+
Spackle.init :with => :spec_formatter
|
197
|
+
end
|
198
|
+
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|