simplabs-excellent 1.2.1 → 1.2.2
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/History.txt +4 -0
- data/VERSION.yml +1 -1
- data/lib/simplabs/excellent.rb +1 -1
- data/spec/checks/abc_metric_method_check_spec.rb +17 -17
- data/spec/checks/assignment_in_conditional_check_spec.rb +18 -18
- data/spec/checks/case_missing_else_check_spec.rb +4 -4
- data/spec/checks/class_line_count_check_spec.rb +8 -8
- data/spec/checks/class_name_check_spec.rb +7 -7
- data/spec/checks/control_coupling_check_spec.rb +14 -14
- data/spec/checks/cyclomatic_complexity_block_check_spec.rb +6 -6
- data/spec/checks/cyclomatic_complexity_method_check_spec.rb +28 -28
- data/spec/checks/duplication_check_spec.rb +24 -24
- data/spec/checks/empty_rescue_body_check_spec.rb +29 -29
- data/spec/checks/flog_block_check_spec.rb +2 -2
- data/spec/checks/flog_class_check_spec.rb +2 -2
- data/spec/checks/flog_method_check_spec.rb +6 -6
- data/spec/checks/for_loop_check_spec.rb +8 -8
- data/spec/checks/method_line_count_check_spec.rb +6 -6
- data/spec/checks/method_name_check_spec.rb +16 -16
- data/spec/checks/module_line_count_check_spec.rb +6 -6
- data/spec/checks/module_name_check_spec.rb +8 -8
- data/spec/checks/nested_iterators_check_spec.rb +4 -4
- data/spec/checks/parameter_number_check_spec.rb +18 -18
- data/spec/checks/rails/attr_accessible_check_spec.rb +10 -10
- data/spec/checks/rails/attr_protected_check_spec.rb +10 -10
- data/spec/checks/singleton_variable_check_spec.rb +6 -6
- metadata +1 -1
| @@ -9,17 +9,17 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do | |
| 9 9 | 
             
              describe '#evaluate' do
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should find a simple block' do
         | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  code = <<-END
         | 
| 13 13 | 
             
                    it 'should be a simple block' do
         | 
| 14 14 | 
             
                      call_foo
         | 
| 15 15 | 
             
                    end
         | 
| 16 16 | 
             
                  END
         | 
| 17 17 |  | 
| 18 | 
            -
                   | 
| 18 | 
            +
                  verify_code_complexity(code, 1)
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                it 'should find a block with multiple paths' do
         | 
| 22 | 
            -
                   | 
| 22 | 
            +
                  code = <<-END
         | 
| 23 23 | 
             
                    it 'should be a complex block' do
         | 
| 24 24 | 
             
                      if some_condition
         | 
| 25 25 | 
             
                        call_foo
         | 
| @@ -29,13 +29,13 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityBlockCheck do | |
| 29 29 | 
             
                    end
         | 
| 30 30 | 
             
                  END
         | 
| 31 31 |  | 
| 32 | 
            -
                   | 
| 32 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 35 | 
             
              end
         | 
| 36 36 |  | 
| 37 | 
            -
              def  | 
| 38 | 
            -
                @excellent. | 
| 37 | 
            +
              def verify_code_complexity(code, score)
         | 
| 38 | 
            +
                @excellent.check_code(code)
         | 
| 39 39 | 
             
                warnings = @excellent.warnings
         | 
| 40 40 |  | 
| 41 41 | 
             
                warnings.should_not be_empty
         | 
| @@ -9,27 +9,27 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 9 9 | 
             
              describe '#evaluate' do
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should find an if block' do
         | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  code = <<-END
         | 
| 13 13 | 
             
                    def method_name
         | 
| 14 14 | 
             
                      call_foo if some_condition
         | 
| 15 15 | 
             
                    end
         | 
| 16 16 | 
             
                  END
         | 
| 17 17 |  | 
| 18 | 
            -
                   | 
| 18 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                it 'should find an unless block' do
         | 
| 22 | 
            -
                   | 
| 22 | 
            +
                  code = <<-END
         | 
| 23 23 | 
             
                    def method_name
         | 
| 24 24 | 
             
                      call_foo unless some_condition
         | 
| 25 25 | 
             
                    end
         | 
| 26 26 | 
             
                  END
         | 
| 27 27 |  | 
| 28 | 
            -
                   | 
| 28 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| 31 31 | 
             
                it 'should find an elsif block' do
         | 
| 32 | 
            -
                   | 
| 32 | 
            +
                  code = <<-END
         | 
| 33 33 | 
             
                    def method_name
         | 
| 34 34 | 
             
                      if first_condition then
         | 
| 35 35 | 
             
                        call_foo
         | 
| @@ -41,21 +41,21 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 41 41 | 
             
                    end
         | 
| 42 42 | 
             
                  END
         | 
| 43 43 |  | 
| 44 | 
            -
                   | 
| 44 | 
            +
                  verify_code_complexity(code, 3)
         | 
| 45 45 | 
             
                end
         | 
| 46 46 |  | 
| 47 47 | 
             
                it 'should find a ternary operator' do
         | 
| 48 | 
            -
                   | 
| 48 | 
            +
                  code = <<-END
         | 
| 49 49 | 
             
                    def method_name
         | 
| 50 50 | 
             
                      value = some_condition ? 1 : 2
         | 
| 51 51 | 
             
                    end
         | 
| 52 52 | 
             
                  END
         | 
| 53 53 |  | 
| 54 | 
            -
                   | 
| 54 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 55 55 | 
             
                end
         | 
| 56 56 |  | 
| 57 57 | 
             
                it 'should find a while loop' do
         | 
| 58 | 
            -
                   | 
| 58 | 
            +
                  code = <<-END
         | 
| 59 59 | 
             
                    def method_name
         | 
| 60 60 | 
             
                      while some_condition do
         | 
| 61 61 | 
             
                        call_foo
         | 
| @@ -63,11 +63,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 63 63 | 
             
                    end
         | 
| 64 64 | 
             
                  END
         | 
| 65 65 |  | 
| 66 | 
            -
                   | 
| 66 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 67 67 | 
             
                end
         | 
| 68 68 |  | 
| 69 69 | 
             
                it 'should find an until loop' do
         | 
| 70 | 
            -
                   | 
| 70 | 
            +
                  code = <<-END
         | 
| 71 71 | 
             
                    def method_name
         | 
| 72 72 | 
             
                      until some_condition do
         | 
| 73 73 | 
             
                        call_foo
         | 
| @@ -75,11 +75,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 75 75 | 
             
                    end
         | 
| 76 76 | 
             
                  END
         | 
| 77 77 |  | 
| 78 | 
            -
                   | 
| 78 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 79 79 | 
             
                end
         | 
| 80 80 |  | 
| 81 81 | 
             
                it 'should find a for loop' do
         | 
| 82 | 
            -
                   | 
| 82 | 
            +
                  code = <<-END
         | 
| 83 83 | 
             
                    def method_name
         | 
| 84 84 | 
             
                      for i in 1..2 do
         | 
| 85 85 | 
             
                        call_method
         | 
| @@ -87,11 +87,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 87 87 | 
             
                    end
         | 
| 88 88 | 
             
                  END
         | 
| 89 89 |  | 
| 90 | 
            -
                   | 
| 90 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| 93 93 | 
             
                it 'should find a rescue block' do
         | 
| 94 | 
            -
                   | 
| 94 | 
            +
                  code = <<-END
         | 
| 95 95 | 
             
                    def method_name
         | 
| 96 96 | 
             
                      begin
         | 
| 97 97 | 
             
                        call_foo
         | 
| @@ -101,11 +101,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 101 101 | 
             
                    end
         | 
| 102 102 | 
             
                  END
         | 
| 103 103 |  | 
| 104 | 
            -
                   | 
| 104 | 
            +
                  verify_code_complexity(code, 2)
         | 
| 105 105 | 
             
                end
         | 
| 106 106 |  | 
| 107 107 | 
             
                it 'should find a case and when block' do
         | 
| 108 | 
            -
                   | 
| 108 | 
            +
                  code = <<-END
         | 
| 109 109 | 
             
                    def method_name
         | 
| 110 110 | 
             
                      case value
         | 
| 111 111 | 
             
                        when 1
         | 
| @@ -116,7 +116,7 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 116 116 | 
             
                    end
         | 
| 117 117 | 
             
                  END
         | 
| 118 118 |  | 
| 119 | 
            -
                   | 
| 119 | 
            +
                  verify_code_complexity(code, 4)
         | 
| 120 120 | 
             
                end
         | 
| 121 121 |  | 
| 122 122 | 
             
                describe 'when processing operators' do
         | 
| @@ -124,13 +124,13 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 124 124 | 
             
                  ['&&', 'and', '||', 'or'].each do |operator|
         | 
| 125 125 |  | 
| 126 126 | 
             
                    it "should find #{operator}" do
         | 
| 127 | 
            -
                       | 
| 127 | 
            +
                      code = <<-END
         | 
| 128 128 | 
             
                        def method_name
         | 
| 129 129 | 
             
                          call_foo #{operator} call_bar
         | 
| 130 130 | 
             
                        end
         | 
| 131 131 | 
             
                      END
         | 
| 132 132 |  | 
| 133 | 
            -
                       | 
| 133 | 
            +
                      verify_code_complexity(code, 2)
         | 
| 134 134 | 
             
                    end
         | 
| 135 135 |  | 
| 136 136 | 
             
                  end
         | 
| @@ -138,7 +138,7 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 138 138 | 
             
                end
         | 
| 139 139 |  | 
| 140 140 | 
             
                it 'should deal with nested if blocks containing && and ||' do
         | 
| 141 | 
            -
                   | 
| 141 | 
            +
                  code = <<-END
         | 
| 142 142 | 
             
                    def method_name
         | 
| 143 143 | 
             
                      if first_condition then
         | 
| 144 144 | 
             
                        call_foo if second_condition && third_condition
         | 
| @@ -147,11 +147,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 147 147 | 
             
                    end
         | 
| 148 148 | 
             
                  END
         | 
| 149 149 |  | 
| 150 | 
            -
                   | 
| 150 | 
            +
                  verify_code_complexity(code, 6)
         | 
| 151 151 | 
             
                end
         | 
| 152 152 |  | 
| 153 153 | 
             
                it 'should count stupid nested if and else blocks' do
         | 
| 154 | 
            -
                   | 
| 154 | 
            +
                  code = <<-END
         | 
| 155 155 | 
             
                    def method_name
         | 
| 156 156 | 
             
                      if first_condition then
         | 
| 157 157 | 
             
                        call_foo
         | 
| @@ -166,11 +166,11 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 166 166 | 
             
                    end
         | 
| 167 167 | 
             
                  END
         | 
| 168 168 |  | 
| 169 | 
            -
                   | 
| 169 | 
            +
                  verify_code_complexity(code, 5)
         | 
| 170 170 | 
             
                end
         | 
| 171 171 |  | 
| 172 172 | 
             
                it 'should also work on singleton methods' do
         | 
| 173 | 
            -
                   | 
| 173 | 
            +
                  code = <<-END
         | 
| 174 174 | 
             
                    class Class
         | 
| 175 175 | 
             
                      def self.method_name
         | 
| 176 176 | 
             
                        if first_condition then
         | 
| @@ -186,7 +186,7 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 186 186 | 
             
                      end
         | 
| 187 187 | 
             
                    end
         | 
| 188 188 | 
             
                  END
         | 
| 189 | 
            -
                  @excellent. | 
| 189 | 
            +
                  @excellent.check_code(code)
         | 
| 190 190 | 
             
                  warnings = @excellent.warnings
         | 
| 191 191 |  | 
| 192 192 | 
             
                  warnings.should_not be_empty
         | 
| @@ -197,8 +197,8 @@ describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do | |
| 197 197 |  | 
| 198 198 | 
             
              end
         | 
| 199 199 |  | 
| 200 | 
            -
              def  | 
| 201 | 
            -
                @excellent. | 
| 200 | 
            +
              def verify_code_complexity(code, score)
         | 
| 201 | 
            +
                @excellent.check_code(code)
         | 
| 202 202 | 
             
                warnings = @excellent.warnings
         | 
| 203 203 |  | 
| 204 204 | 
             
                warnings.should_not be_empty
         | 
| @@ -9,99 +9,99 @@ describe Simplabs::Excellent::Checks::DuplicationCheck do | |
| 9 9 | 
             
              describe '#evaluate' do
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should accept multiple calls to new' do
         | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  code = <<-END
         | 
| 13 13 | 
             
                    def double_thing
         | 
| 14 14 | 
             
                      @thing.new + @thing.new
         | 
| 15 15 | 
             
                    end
         | 
| 16 16 | 
             
                  END
         | 
| 17 | 
            -
                  @excellent. | 
| 17 | 
            +
                  @excellent.check_code(code)
         | 
| 18 18 | 
             
                  warnings = @excellent.warnings
         | 
| 19 19 |  | 
| 20 20 | 
             
                  warnings.should be_empty
         | 
| 21 21 | 
             
                end
         | 
| 22 22 |  | 
| 23 23 | 
             
                it 'should reject multiple calls to the same method and receiver' do
         | 
| 24 | 
            -
                   | 
| 24 | 
            +
                  code = <<-END
         | 
| 25 25 | 
             
                    def double_thing
         | 
| 26 26 | 
             
                      @other.thing + @other.thing
         | 
| 27 27 | 
             
                    end
         | 
| 28 28 | 
             
                  END
         | 
| 29 29 |  | 
| 30 | 
            -
                  verify_warning_found( | 
| 30 | 
            +
                  verify_warning_found(code, '@other.thing')
         | 
| 31 31 | 
             
                end
         | 
| 32 32 |  | 
| 33 33 | 
             
                it 'should reject multiple calls to the same lvar' do
         | 
| 34 | 
            -
                   | 
| 34 | 
            +
                  code = <<-END
         | 
| 35 35 | 
             
                    def double_thing
         | 
| 36 36 | 
             
                      thing[1] + thing[2]
         | 
| 37 37 | 
             
                    end
         | 
| 38 38 | 
             
                  END
         | 
| 39 39 |  | 
| 40 | 
            -
                  verify_warning_found( | 
| 40 | 
            +
                  verify_warning_found(code, 'thing.[]')
         | 
| 41 41 | 
             
                end
         | 
| 42 42 |  | 
| 43 43 | 
             
                it 'should reject multiple calls to the same singleton method' do
         | 
| 44 | 
            -
                   | 
| 44 | 
            +
                  code = <<-END
         | 
| 45 45 | 
             
                    def double_thing
         | 
| 46 46 | 
             
                      Class.thing[1] + Class.thing[2]
         | 
| 47 47 | 
             
                    end
         | 
| 48 48 | 
             
                  END
         | 
| 49 49 |  | 
| 50 | 
            -
                  verify_warning_found( | 
| 50 | 
            +
                  verify_warning_found(code, 'Class.thing')
         | 
| 51 51 | 
             
                end
         | 
| 52 52 |  | 
| 53 53 | 
             
                it 'should reject multiple calls to the same method without a receiver' do
         | 
| 54 | 
            -
                   | 
| 54 | 
            +
                  code = <<-END
         | 
| 55 55 | 
             
                    def double_thing
         | 
| 56 56 | 
             
                      thing + thing
         | 
| 57 57 | 
             
                    end
         | 
| 58 58 | 
             
                  END
         | 
| 59 59 |  | 
| 60 | 
            -
                  verify_warning_found( | 
| 60 | 
            +
                  verify_warning_found(code, 'thing')
         | 
| 61 61 | 
             
                end
         | 
| 62 62 |  | 
| 63 63 | 
             
                it 'should reject multiple calls to the same method with the same parameters' do
         | 
| 64 | 
            -
                   | 
| 64 | 
            +
                  code = <<-END
         | 
| 65 65 | 
             
                    def double_thing
         | 
| 66 66 | 
             
                      thing(1) + thing(1)
         | 
| 67 67 | 
             
                    end
         | 
| 68 68 | 
             
                  END
         | 
| 69 69 |  | 
| 70 | 
            -
                  verify_warning_found( | 
| 70 | 
            +
                  verify_warning_found(code, 'thing')
         | 
| 71 71 | 
             
                end
         | 
| 72 72 |  | 
| 73 73 | 
             
                it 'should reject multiple calls to the same method with different parameters' do
         | 
| 74 | 
            -
                   | 
| 74 | 
            +
                  code = <<-END
         | 
| 75 75 | 
             
                    def double_thing
         | 
| 76 76 | 
             
                      thing(1) + thing(2)
         | 
| 77 77 | 
             
                    end
         | 
| 78 78 | 
             
                  END
         | 
| 79 79 |  | 
| 80 | 
            -
                  verify_warning_found( | 
| 80 | 
            +
                  verify_warning_found(code, 'thing')
         | 
| 81 81 | 
             
                end
         | 
| 82 82 |  | 
| 83 83 | 
             
                it 'should work with singleton methods on objects' do
         | 
| 84 | 
            -
                   | 
| 84 | 
            +
                  code = <<-END
         | 
| 85 85 | 
             
                    def object.double_thing
         | 
| 86 86 | 
             
                      thing(1) + thing(2)
         | 
| 87 87 | 
             
                    end
         | 
| 88 88 | 
             
                  END
         | 
| 89 89 |  | 
| 90 | 
            -
                  verify_warning_found( | 
| 90 | 
            +
                  verify_warning_found(code, 'thing', 'object.double_thing')
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| 93 93 | 
             
                it 'should work with singleton methods on classes' do
         | 
| 94 | 
            -
                   | 
| 94 | 
            +
                  code = <<-END
         | 
| 95 95 | 
             
                    def Class.double_thing
         | 
| 96 96 | 
             
                      thing(1) + thing(2)
         | 
| 97 97 | 
             
                    end
         | 
| 98 98 | 
             
                  END
         | 
| 99 99 |  | 
| 100 | 
            -
                  verify_warning_found( | 
| 100 | 
            +
                  verify_warning_found(code, 'thing', 'Class.double_thing')
         | 
| 101 101 | 
             
                end
         | 
| 102 102 |  | 
| 103 103 | 
             
                it 'should work with singleton methods on classes' do
         | 
| 104 | 
            -
                   | 
| 104 | 
            +
                  code = <<-END
         | 
| 105 105 | 
             
                    class Class
         | 
| 106 106 | 
             
                      def self.double_thing
         | 
| 107 107 | 
             
                        thing(1) + thing(2)
         | 
| @@ -109,11 +109,11 @@ describe Simplabs::Excellent::Checks::DuplicationCheck do | |
| 109 109 | 
             
                    end
         | 
| 110 110 | 
             
                  END
         | 
| 111 111 |  | 
| 112 | 
            -
                  verify_warning_found( | 
| 112 | 
            +
                  verify_warning_found(code, 'thing', 'Class.double_thing', 2)
         | 
| 113 113 | 
             
                end
         | 
| 114 114 |  | 
| 115 115 | 
             
                it 'should also work with blocks' do
         | 
| 116 | 
            -
                   | 
| 116 | 
            +
                  code = <<-END
         | 
| 117 117 | 
             
                    def method
         | 
| 118 118 | 
             
                      double_thing do
         | 
| 119 119 | 
             
                        thing(1) + thing(2)
         | 
| @@ -121,13 +121,13 @@ describe Simplabs::Excellent::Checks::DuplicationCheck do | |
| 121 121 | 
             
                    end
         | 
| 122 122 | 
             
                  END
         | 
| 123 123 |  | 
| 124 | 
            -
                  verify_warning_found( | 
| 124 | 
            +
                  verify_warning_found(code, 'thing', 'block', 2)
         | 
| 125 125 | 
             
                end
         | 
| 126 126 |  | 
| 127 127 | 
             
              end
         | 
| 128 128 |  | 
| 129 | 
            -
              def verify_warning_found( | 
| 130 | 
            -
                @excellent. | 
| 129 | 
            +
              def verify_warning_found(code, statement, method = 'double_thing', line = 1)
         | 
| 130 | 
            +
                @excellent.check_code(code)
         | 
| 131 131 | 
             
                warnings = @excellent.warnings
         | 
| 132 132 |  | 
| 133 133 | 
             
                warnings.should_not be_empty
         | 
| @@ -9,156 +9,156 @@ describe Simplabs::Excellent::Checks::EmptyRescueBodyCheck do | |
| 9 9 | 
             
              describe '#evaluate' do
         | 
| 10 10 |  | 
| 11 11 | 
             
                it 'should accept a rescue body with content and no parameter' do
         | 
| 12 | 
            -
                   | 
| 12 | 
            +
                  code = <<-END
         | 
| 13 13 | 
             
                    begin
         | 
| 14 14 | 
             
                      call_method
         | 
| 15 15 | 
             
                    rescue
         | 
| 16 16 | 
             
                      puts "Recover from the call"
         | 
| 17 17 | 
             
                    end
         | 
| 18 18 | 
             
                  END
         | 
| 19 | 
            -
                  @excellent. | 
| 19 | 
            +
                  @excellent.check_code(code)
         | 
| 20 20 |  | 
| 21 21 | 
             
                  @excellent.warnings.should be_empty
         | 
| 22 22 | 
             
                end
         | 
| 23 23 |  | 
| 24 24 | 
             
                it 'should accept a rescue body with a return' do
         | 
| 25 | 
            -
                   | 
| 25 | 
            +
                  code = <<-END
         | 
| 26 26 | 
             
                    begin
         | 
| 27 27 | 
             
                      call_method
         | 
| 28 28 | 
             
                    rescue
         | 
| 29 29 | 
             
                      return true
         | 
| 30 30 | 
             
                    end
         | 
| 31 31 | 
             
                  END
         | 
| 32 | 
            -
                  @excellent. | 
| 32 | 
            +
                  @excellent.check_code(code)
         | 
| 33 33 |  | 
| 34 34 | 
             
                  @excellent.warnings.should be_empty
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                it "should accept a virtual method call" do
         | 
| 38 | 
            -
                   | 
| 38 | 
            +
                  code = <<-END
         | 
| 39 39 | 
             
                    begin
         | 
| 40 40 | 
             
                      call_method
         | 
| 41 41 | 
             
                    rescue
         | 
| 42 42 | 
             
                      show_error
         | 
| 43 43 | 
             
                    end
         | 
| 44 44 | 
             
                  END
         | 
| 45 | 
            -
                  @excellent. | 
| 45 | 
            +
                  @excellent.check_code(code)
         | 
| 46 46 |  | 
| 47 47 | 
             
                  @excellent.warnings.should be_empty
         | 
| 48 48 | 
             
                end
         | 
| 49 49 |  | 
| 50 | 
            -
                it 'should accept a rescue body with  | 
| 51 | 
            -
                   | 
| 50 | 
            +
                it 'should accept a rescue body with code and a parameter' do
         | 
| 51 | 
            +
                  code = <<-END
         | 
| 52 52 | 
             
                    begin
         | 
| 53 53 | 
             
                      call_method
         | 
| 54 54 | 
             
                    rescue Exception => e
         | 
| 55 55 | 
             
                      puts "Recover from the call"
         | 
| 56 56 | 
             
                    end
         | 
| 57 57 | 
             
                  END
         | 
| 58 | 
            -
                  @excellent. | 
| 58 | 
            +
                  @excellent.check_code(code)
         | 
| 59 59 |  | 
| 60 60 | 
             
                  @excellent.warnings.should be_empty
         | 
| 61 61 | 
             
                end
         | 
| 62 62 |  | 
| 63 63 | 
             
                it 'should accept a rescue body with an assignment' do
         | 
| 64 | 
            -
                   | 
| 64 | 
            +
                  code = <<-END
         | 
| 65 65 | 
             
                    begin
         | 
| 66 66 | 
             
                      call_method
         | 
| 67 67 | 
             
                    rescue Exception => e
         | 
| 68 68 | 
             
                      my_var = 1
         | 
| 69 69 | 
             
                    end
         | 
| 70 70 | 
             
                  END
         | 
| 71 | 
            -
                  @excellent. | 
| 71 | 
            +
                  @excellent.check_code(code)
         | 
| 72 72 |  | 
| 73 73 | 
             
                  @excellent.warnings.should be_empty
         | 
| 74 74 | 
             
                end
         | 
| 75 75 |  | 
| 76 76 | 
             
                it 'should accept a rescue body with an attribute assignment' do
         | 
| 77 | 
            -
                   | 
| 77 | 
            +
                  code = <<-END
         | 
| 78 78 | 
             
                    begin
         | 
| 79 79 | 
             
                      call_method
         | 
| 80 80 | 
             
                    rescue Exception => e
         | 
| 81 81 | 
             
                      self.var = 1
         | 
| 82 82 | 
             
                    end
         | 
| 83 83 | 
             
                  END
         | 
| 84 | 
            -
                  @excellent. | 
| 84 | 
            +
                  @excellent.check_code(code)
         | 
| 85 85 |  | 
| 86 86 | 
             
                  @excellent.warnings.should be_empty
         | 
| 87 87 | 
             
                end
         | 
| 88 88 |  | 
| 89 89 | 
             
                it 'should accept an inline rescue statement' do
         | 
| 90 | 
            -
                   | 
| 90 | 
            +
                  code = <<-END
         | 
| 91 91 | 
             
                    value = call_method rescue 1
         | 
| 92 92 | 
             
                  END
         | 
| 93 | 
            -
                  @excellent. | 
| 93 | 
            +
                  @excellent.check_code(code)
         | 
| 94 94 |  | 
| 95 95 | 
             
                  @excellent.warnings.should be_empty
         | 
| 96 96 | 
             
                end
         | 
| 97 97 |  | 
| 98 98 | 
             
                it 'should accept an empty array as a statement' do
         | 
| 99 | 
            -
                   | 
| 99 | 
            +
                  code = <<-END
         | 
| 100 100 | 
             
                    value = call_method rescue []
         | 
| 101 101 | 
             
                  END
         | 
| 102 102 |  | 
| 103 | 
            -
                  @excellent. | 
| 103 | 
            +
                  @excellent.check_code(code)
         | 
| 104 104 |  | 
| 105 105 | 
             
                  @excellent.warnings.should be_empty
         | 
| 106 106 | 
             
                end
         | 
| 107 107 |  | 
| 108 108 | 
             
                it 'should accept an empty hash as a statement' do
         | 
| 109 | 
            -
                   | 
| 109 | 
            +
                  code = <<-END
         | 
| 110 110 | 
             
                    value = call_method rescue {}
         | 
| 111 111 | 
             
                  END
         | 
| 112 112 |  | 
| 113 | 
            -
                  @excellent. | 
| 113 | 
            +
                  @excellent.check_code(code)
         | 
| 114 114 |  | 
| 115 115 | 
             
                  @excellent.warnings.should be_empty
         | 
| 116 116 | 
             
                end
         | 
| 117 117 |  | 
| 118 118 | 
             
                it 'should accept a boolean as a statement' do
         | 
| 119 | 
            -
                   | 
| 119 | 
            +
                  code = <<-END
         | 
| 120 120 | 
             
                    value = call_method rescue false
         | 
| 121 121 | 
             
                  END
         | 
| 122 | 
            -
                  @excellent. | 
| 122 | 
            +
                  @excellent.check_code(code)
         | 
| 123 123 |  | 
| 124 124 | 
             
                  @excellent.warnings.should be_empty
         | 
| 125 125 | 
             
                end
         | 
| 126 126 |  | 
| 127 127 | 
             
                it 'should accept nil as a statement' do
         | 
| 128 | 
            -
                   | 
| 128 | 
            +
                  code = <<-END
         | 
| 129 129 | 
             
                    value = call_method rescue nil
         | 
| 130 130 | 
             
                  END
         | 
| 131 | 
            -
                  @excellent. | 
| 131 | 
            +
                  @excellent.check_code(code)
         | 
| 132 132 |  | 
| 133 133 | 
             
                  @excellent.warnings.should be_empty
         | 
| 134 134 | 
             
                end
         | 
| 135 135 |  | 
| 136 136 | 
             
                it 'should reject an empty rescue block with no parameter' do
         | 
| 137 | 
            -
                   | 
| 137 | 
            +
                  code = <<-END
         | 
| 138 138 | 
             
                    begin
         | 
| 139 139 | 
             
                      call_method
         | 
| 140 140 | 
             
                    rescue
         | 
| 141 141 | 
             
                    end
         | 
| 142 142 | 
             
                  END
         | 
| 143 143 |  | 
| 144 | 
            -
                  verify_warning_found( | 
| 144 | 
            +
                  verify_warning_found(code)
         | 
| 145 145 | 
             
                end
         | 
| 146 146 |  | 
| 147 147 | 
             
                it 'should reject an empty rescue block with a parameter' do
         | 
| 148 | 
            -
                   | 
| 148 | 
            +
                  code = <<-END
         | 
| 149 149 | 
             
                    begin
         | 
| 150 150 | 
             
                      call_method
         | 
| 151 151 | 
             
                    rescue Exception => e
         | 
| 152 152 | 
             
                    end
         | 
| 153 153 | 
             
                  END
         | 
| 154 154 |  | 
| 155 | 
            -
                  verify_warning_found( | 
| 155 | 
            +
                  verify_warning_found(code)
         | 
| 156 156 | 
             
                end
         | 
| 157 157 |  | 
| 158 158 | 
             
              end
         | 
| 159 159 |  | 
| 160 | 
            -
              def verify_warning_found( | 
| 161 | 
            -
                @excellent. | 
| 160 | 
            +
              def verify_warning_found(code)
         | 
| 161 | 
            +
                @excellent.check_code(code)
         | 
| 162 162 | 
             
                warnings = @excellent.warnings
         | 
| 163 163 |  | 
| 164 164 | 
             
                warnings.should_not be_empty
         |