Make only one assumption per context.

This commit is contained in:
Michael Kessler 2011-10-11 11:06:30 +02:00
parent 8891776e34
commit 8527cf40e3

View File

@ -70,153 +70,157 @@ describe Guard::Watcher do
end
end
context "with a watcher action without parameter for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
context "with a watcher action without parameter" do
context "for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
end
it "returns a single file specified within the action" do
described_class.match_files(@guard, ['spec_helper.rb']).should == ['spec']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar']
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
end
end
it "returns a single file specified within the action" do
described_class.match_files(@guard, ['spec_helper.rb']).should == ['spec']
end
context 'for a watcher that matches information objects' do
before(:all) do
@guard_any_return.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns a single file specified within the action" do
described_class.match_files(@guard_any_return, ['spec_helper.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['spec_helper.rb']).empty?.should == false
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['spec_helper.rb', 'array.rb']).should == ['spec', 'foo', 'bar']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar'}]
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['spec_helper.rb', 'array.rb']).should == ['spec', ['foo', 'bar']]
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns the evaluated addition argument in an array" do
described_class.match_files(@guard_any_return, ['addition.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['addition.rb'])[0].should == 2
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
end
end
end
context 'with a watcher action without parameter for a watcher that matches information objects' do
before(:all) do
@guard_any_return.watchers = [
described_class.new('spec_helper.rb', lambda { 'spec' }),
described_class.new('addition.rb', lambda { 1 + 1 }),
described_class.new('hash.rb', lambda { Hash[:foo, 'bar'] }),
described_class.new('array.rb', lambda { ['foo', 'bar'] }),
described_class.new('blank.rb', lambda { '' }),
described_class.new(/^uptime\.rb/, lambda { `uptime > /dev/null` })
]
context "with a watcher action that takes a parameter" do
context "for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| 1 + 1 }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar'] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar'] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
end
end
it "returns a single file specified within the action" do
described_class.match_files(@guard_any_return, ['spec_helper.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['spec_helper.rb']).empty?.should == false
end
context "for a watcher that matches information objects" do
before(:all) do
@guard_any_return.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| (1 + 1).to_s + m[0] }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar', :file_name, m[0]] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar', m[0]] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar'}]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['spec_helper.rb', 'array.rb']).should == ['spec', ['foo', 'bar']]
end
it "returns a hash specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar', :file_name => 'hash.rb'}]
end
it "returns the evaluated addition argument in an array" do
described_class.match_files(@guard_any_return, ['addition.rb']).class.should == Array
described_class.match_files(@guard_any_return, ['addition.rb'])[0].should == 2
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', ['foo', 'bar', "array.rb"]]
end
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
it "returns the evaluated addition argument + the path" do
described_class.match_files(@guard_any_return, ['addition.rb']).should == ["2addition.rb"]
end
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
end
end
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
context "with a watcher action that takes a parameter for a watcher that matches file strings" do
before(:all) do
@guard.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| 1 + 1 }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar'] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar'] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns multiple files specified within the action" do
described_class.match_files(@guard, ['hash.rb']).should == ['foo', 'bar']
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', 'foo', 'bar']
end
it "returns nothing if the action returns something other than a string or an array of strings" do
described_class.match_files(@guard, ['addition.rb']).should == []
end
it "returns nothing if the action response is empty" do
described_class.match_files(@guard, ['blank.rb']).should == []
end
it "returns nothing if the action returns nothing" do
described_class.match_files(@guard, ['uptime.rb']).should == []
end
end
context "with a watcher action that takes a parameter for a watcher that matches information objects" do
before(:all) do
@guard_any_return.watchers = [
described_class.new(%r{lib/(.*)\.rb}, lambda { |m| "spec/#{m[1]}_spec.rb" }),
described_class.new(/addition(.*)\.rb/, lambda { |m| (1 + 1).to_s + m[0] }),
described_class.new('hash.rb', lambda { |m| Hash[:foo, 'bar', :file_name, m[0]] }),
described_class.new(/array(.*)\.rb/, lambda { |m| ['foo', 'bar', m[0]] }),
described_class.new(/blank(.*)\.rb/, lambda { |m| '' }),
described_class.new(/uptime(.*)\.rb/, lambda { |m| `uptime > /dev/null` })
]
end
it "returns a substituted single file specified within the action" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb']).should == ['spec/my_wonderful_lib_spec.rb']
end
it "returns a hash specified within the action" do
described_class.match_files(@guard_any_return, ['hash.rb']).should == [{:foo => 'bar', :file_name => 'hash.rb'}]
end
it "returns multiple files by combining the results of different actions" do
described_class.match_files(@guard_any_return, ['lib/my_wonderful_lib.rb', 'array.rb']).should == ['spec/my_wonderful_lib_spec.rb', ['foo', 'bar', "array.rb"]]
end
it "returns the evaluated addition argument + the path" do
described_class.match_files(@guard_any_return, ['addition.rb']).should == ["2addition.rb"]
end
it "returns nothing if the action response is empty string" do
described_class.match_files(@guard_any_return, ['blank.rb']).should == ['']
end
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
it "returns nothing if the action returns empty string" do
described_class.match_files(@guard_any_return, ['uptime.rb']).should == ['']
end
end
end