|
1 | 1 | require "spec_helper"
|
2 | 2 |
|
3 | 3 | describe Autotest::Rspec2 do
|
4 |
| - describe "commands" do |
5 |
| - before(:each) do |
6 |
| - @rspec_autotest = Autotest::Rspec2.new |
7 |
| - @rspec_autotest.stub!(:ruby).and_return "ruby" |
| 4 | + let(:rspec_autotest) { Autotest::Rspec2.new } |
| 5 | + let(:spec_cmd) { File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec')) } |
| 6 | + let(:ruby_cmd) { "ruby" } |
8 | 7 |
|
9 |
| - @ruby = @rspec_autotest.ruby |
10 |
| - @spec_cmd = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec')) |
| 8 | + describe "commands" do |
| 9 | + before do |
| 10 | + rspec_autotest.stub(:ruby => ruby_cmd) |
11 | 11 | files = %w[file_one file_two]
|
12 | 12 | @files_to_test = {
|
13 | 13 | files[0] => [],
|
14 | 14 | files[1] => []
|
15 | 15 | }
|
16 | 16 | # this is not the inner representation of Autotest!
|
17 |
| - @rspec_autotest.files_to_test = @files_to_test |
| 17 | + rspec_autotest.files_to_test = @files_to_test |
18 | 18 | @to_test = files.map { |f| File.expand_path(f) }.join ' '
|
19 | 19 | end
|
20 | 20 |
|
21 |
| - it "should make the appropriate test command" do |
22 |
| - actual = @rspec_autotest.make_test_cmd(@files_to_test) |
23 |
| - expected = /#{@ruby}.*#{@spec_cmd} (.*)/ |
| 21 | + it "makes the appropriate test command" do |
| 22 | + actual_command = rspec_autotest.make_test_cmd(@files_to_test) |
| 23 | + expected_command = /#{ruby_cmd}.*#{spec_cmd} (.*)/ |
24 | 24 |
|
25 |
| - actual.should match(expected) |
| 25 | + actual_command.should match(expected_command) |
26 | 26 |
|
27 |
| - actual =~ expected |
| 27 | + actual_command =~ expected_command |
28 | 28 | $1.should =~ /#{File.expand_path('file_one')}/
|
29 | 29 | $1.should =~ /#{File.expand_path('file_two')}/
|
30 | 30 | end
|
31 | 31 |
|
32 |
| - it "should return a blank command for no files" do |
33 |
| - @rspec_autotest.make_test_cmd({}).should == '' |
| 32 | + it "returns a blank command for no files" do |
| 33 | + rspec_autotest.make_test_cmd({}).should eq('') |
34 | 34 | end
|
35 | 35 |
|
36 |
| - it "should quote the paths of files to test" do |
37 |
| - cmd = @rspec_autotest.make_test_cmd(@files_to_test) |
| 36 | + it "quotes the paths of files to test" do |
| 37 | + cmd = rspec_autotest.make_test_cmd(@files_to_test) |
38 | 38 | @files_to_test.keys.each do |file_to_test|
|
39 |
| - cmd.should =~ /'#{File.expand_path(file_to_test)}'/ |
| 39 | + cmd.should match(/'#{File.expand_path(file_to_test)}'/) |
40 | 40 | end
|
41 | 41 | end
|
42 | 42 | end
|
43 | 43 |
|
44 | 44 | describe "mappings" do
|
45 |
| - |
46 |
| - before(:each) do |
| 45 | + before do |
47 | 46 | @lib_file = "lib/something.rb"
|
48 | 47 | @spec_file = "spec/something_spec.rb"
|
49 |
| - @rspec_autotest = Autotest::Rspec2.new |
50 |
| - @rspec_autotest.hook :initialize |
| 48 | + rspec_autotest.hook :initialize |
51 | 49 | end
|
52 | 50 |
|
53 |
| - it "should find the spec file for a given lib file" do |
54 |
| - @rspec_autotest.should map_specs([@spec_file]).to(@lib_file) |
| 51 | + it "finds the spec file for a given lib file" do |
| 52 | + rspec_autotest.should map_specs([@spec_file]).to(@lib_file) |
55 | 53 | end
|
56 | 54 |
|
57 |
| - it "should find the spec file if given a spec file" do |
58 |
| - @rspec_autotest.should map_specs([@spec_file]).to(@spec_file) |
| 55 | + it "finds the spec file if given a spec file" do |
| 56 | + rspec_autotest.should map_specs([@spec_file]).to(@spec_file) |
59 | 57 | end
|
60 | 58 |
|
61 |
| - it "should ignore files in spec dir that aren't specs" do |
62 |
| - @rspec_autotest.should map_specs([]).to("spec/spec_helper.rb") |
| 59 | + it "ignores files in spec dir that aren't specs" do |
| 60 | + rspec_autotest.should map_specs([]).to("spec/spec_helper.rb") |
63 | 61 | end
|
64 | 62 |
|
65 |
| - it "should ignore untracked files (in @file)" do |
66 |
| - @rspec_autotest.should map_specs([]).to("lib/untracked_file") |
| 63 | + it "ignores untracked files (in @file)" do |
| 64 | + rspec_autotest.should map_specs([]).to("lib/untracked_file") |
67 | 65 | end
|
68 | 66 | end
|
69 | 67 |
|
70 | 68 | describe "consolidating failures" do
|
71 |
| - before(:each) do |
72 |
| - @rspec_autotest = Autotest::Rspec2.new |
73 |
| - |
| 69 | + before do |
74 | 70 | @spec_file = "spec/autotest/some_spec.rb"
|
75 |
| - @rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now}) |
76 |
| - @rspec_autotest.stub!(:find_files_to_test).and_return true |
| 71 | + rspec_autotest.instance_variable_set("@files", {@spec_file => Time.now}) |
| 72 | + rspec_autotest.stub!(:find_files_to_test).and_return true |
77 | 73 | end
|
78 | 74 |
|
79 |
| - it "should return no failures if no failures were given in the output" do |
80 |
| - @rspec_autotest.consolidate_failures([[]]).should == {} |
| 75 | + it "returns no failures if no failures were given in the output" do |
| 76 | + rspec_autotest.consolidate_failures([[]]).should == {} |
81 | 77 | end
|
82 | 78 |
|
83 |
| - it "should return a hash with the spec filename => spec name for each failure or error" do |
84 |
| - @rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb" |
| 79 | + it "returns a hash with the spec filename => spec name for each failure or error" do |
| 80 | + rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb" |
85 | 81 | failures = [
|
86 | 82 | [
|
87 | 83 | "false should be false",
|
88 | 84 | "#{@spec_file}"
|
89 | 85 | ]
|
90 | 86 | ]
|
91 |
| - @rspec_autotest.consolidate_failures(failures).should == { |
| 87 | + rspec_autotest.consolidate_failures(failures).should == { |
92 | 88 | @spec_file => ["false should be false"]
|
93 | 89 | }
|
94 | 90 | end
|
95 | 91 |
|
96 |
| - it "should not include the subject file" do |
| 92 | + it "does not include the subject file" do |
97 | 93 | subject_file = "lib/autotest/some.rb"
|
98 |
| - @rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb" |
| 94 | + rspec_autotest.stub!(:test_files_for).and_return "spec/autotest/some_spec.rb" |
99 | 95 | failures = [
|
100 | 96 | [
|
101 | 97 | "false should be false",
|
102 | 98 | "expected: true,\n got: false (using ==)\n#{subject_file}:143:\n#{@spec_file}:203:"
|
103 | 99 | ]
|
104 | 100 | ]
|
105 |
| - @rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file) |
| 101 | + rspec_autotest.consolidate_failures(failures).keys.should_not include(subject_file) |
106 | 102 | end
|
107 | 103 | end
|
108 | 104 |
|
109 | 105 | describe "normalizing file names" do
|
110 |
| - it "should ensure that a single file appears in files_to_test only once" do |
111 |
| - @rspec_autotest = Autotest::Rspec2.new |
| 106 | + it "ensures that a single file appears in files_to_test only once" do |
112 | 107 | @files_to_test = {}
|
113 | 108 | ['filename.rb', './filename.rb', File.expand_path('filename.rb')].each do |file|
|
114 | 109 | @files_to_test[file] = []
|
115 | 110 | end
|
116 |
| - @rspec_autotest.normalize(@files_to_test).should have(1).file |
| 111 | + rspec_autotest.normalize(@files_to_test).should have(1).file |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + describe "ruby command" do |
| 116 | + context "using bundler" do |
| 117 | + it "returns 'bundle exec'" do |
| 118 | + File.stub(:exists?).with("./Gemfile") { true } |
| 119 | + rspec_autotest.ruby.should eq("bundle exec") |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + context "not using bundler" do |
| 124 | + it "returns the ruby command generated by Autotest" do |
| 125 | + autotest = Autotest.new |
| 126 | + autotest_ruby_command = autotest.ruby |
| 127 | + File.stub(:exists?).with("./Gemfile") { false } |
| 128 | + rspec_autotest.ruby.should eq(autotest_ruby_command) |
| 129 | + end |
117 | 130 | end
|
118 | 131 | end
|
119 | 132 | end
|
0 commit comments