Sha256: b6d9c54815c228300dbf629e4f90014589dd94598f76af44b5dc44db1d361df7

Contents?: true

Size: 1.95 KB

Versions: 11

Compression:

Stored size: 1.95 KB

Contents

require 'spec_helper'

module RailsBestPractices
  module Reviews
    describe ReplaceInstanceVariableWithLocalVariableReview do
      let(:runner) { Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new) }

      it "should replace instance variable with local varialbe" do
        content = <<-EOF
        <%= @post.title %>
        EOF
        runner.review('app/views/posts/_post.html.erb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/views/posts/_post.html.erb:1 - replace instance variable with local variable")
      end

      it "should replace instance variable with local varialbe in haml file" do
        content = <<-EOF
= @post.title
        EOF
        runner.review('app/views/posts/_post.html.haml', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/views/posts/_post.html.haml:1 - replace instance variable with local variable")
      end

      it "should replace instance variable with local varialbe in slim file" do
        content = <<-EOF
= @post.title
        EOF
        runner.review('app/views/posts/_post.html.slim', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/views/posts/_post.html.slim:1 - replace instance variable with local variable")
      end

      it "should not replace instance variable with local varialbe" do
        content = <<-EOF
        <%= post.title %>
        EOF
        runner.review('app/views/posts/_post.html.erb', content)
        expect(runner.errors.size).to eq(0)
      end

      it "should not check ignored files" do
        runner = Core::Runner.new(reviews: ReplaceInstanceVariableWithLocalVariableReview.new(ignored_files: /views\/posts/))
        content = <<-EOF
        <%= @post.title %>
        EOF
        runner.review('app/views/posts/_post.html.erb', content)
        expect(runner.errors.size).to eq(0)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.18.1 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.18.0 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.17.0 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.16.0 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.7 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.6 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.4 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.3 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.2 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
rails_best_practices-1.15.1 spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb