Sha256: 897b3ee3ec3cfd455e975fb5d69752cd2d5e1b454a881a3f4cafe1a688d751b6

Contents?: true

Size: 1.38 KB

Versions: 23

Compression:

Stored size: 1.38 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../spec_helper')

describe RailsBestPractices::Checks::LawOfDemeterCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::LawOfDemeterCheck.new)

    content = <<-EOF
    class Invoice < ActiveRecord::Base
      belongs_to :user
    end
    EOF
    @runner.check('app/models/invoice.rb', content)
  end

  it "should law of demeter" do
    content = <<-EOF
    <%= @invoice.user.name %>
    <%= @invoice.user.address %>
    <%= @invoice.user.cellphone %>
    EOF
    @runner.check('app/views/invoices/show.html.erb', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/views/invoices/show.html.erb:1 - law of demeter"
  end

  it "should law of demeter" do
    content = <<-EOF
= @invoice.user.name
= @invoice.user.address
= @invoice.user.cellphone
    EOF
    @runner.check('app/views/invoices/show.html.haml', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/views/invoices/show.html.haml:1 - law of demeter"
  end

  it "should no law of demeter" do
    content = <<-EOF
    <%= @invoice.user_name %>
    <%= @invoice.user_address %>
    <%= @invoice.user_cellphone %>
    EOF
    @runner.check('app/views/invoices/show.html.erb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rails_best_practices-0.3.23 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.22 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.21 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.20 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.19 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.18 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.17 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.16 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.15 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.14 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.13 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.12 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.11 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.10 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.9 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.8 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.7 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.6 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.5 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb
rails_best_practices-0.3.4 spec/rails_best_practices/checks/law_of_demeter_check_spec.rb