diff --git a/lib/arel/algebra/extensions/class.rb b/lib/arel/algebra/extensions/class.rb index 56cad3aaa8..d0894931da 100644 --- a/lib/arel/algebra/extensions/class.rb +++ b/lib/arel/algebra/extensions/class.rb @@ -2,7 +2,7 @@ module Arel module ClassExtensions def attributes(*attrs) @attributes = attrs - attr_reader *attrs + attr_reader(*attrs) end def deriving(*methods) diff --git a/lib/arel/session.rb b/lib/arel/session.rb index cf04e8a93a..d844cd7423 100644 --- a/lib/arel/session.rb +++ b/lib/arel/session.rb @@ -5,16 +5,22 @@ module Arel alias_method :manufacture, :new def start - if @started + if defined?(@started) && @started yield else begin @started = true @instance = manufacture - metaclass.send :alias_method, :new, :instance + metaclass.class_eval do + undef :new + alias_method :new, :instance + end yield ensure - metaclass.send :alias_method, :new, :manufacture + metaclass.class_eval do + undef :new + alias_method :new, :manufacture + end @started = false end end diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb index c917520158..01917842f6 100644 --- a/spec/arel/algebra/unit/predicates/equality_spec.rb +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -11,7 +11,7 @@ module Arel describe '==' do it "obtains if attribute1 and attribute2 are identical" do - Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) + check Equality.new(@attribute1, @attribute2).should == Equality.new(@attribute1, @attribute2) Equality.new(@attribute1, @attribute2).should_not == Equality.new(@attribute1, @attribute1) end diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index cd484007e1..93b661c6fc 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -73,10 +73,8 @@ module Arel describe 'when dividing two matching attributes' do it 'returns a the highest score for the most similar attributes' do - (@aliased_relation[:id] / @relation[:id]) \ - .should == (@aliased_relation[:id] / @relation[:id]) - (@aliased_relation[:id] / @relation[:id]) \ - .should < (@aliased_relation[:id] / @aliased_relation[:id]) + check((@aliased_relation[:id] / @relation[:id]).should == (@aliased_relation[:id] / @relation[:id])) + (@aliased_relation[:id] / @relation[:id]).should < (@aliased_relation[:id] / @aliased_relation[:id]) end end end diff --git a/spec/arel/algebra/unit/relations/alias_spec.rb b/spec/arel/algebra/unit/relations/alias_spec.rb index 2aa4d52d99..eaf31652b9 100644 --- a/spec/arel/algebra/unit/relations/alias_spec.rb +++ b/spec/arel/algebra/unit/relations/alias_spec.rb @@ -8,7 +8,7 @@ module Arel describe '==' do it "obtains if the objects are the same" do - Alias.new(@relation).should_not == Alias.new(@relation) + check Alias.new(@relation).should_not == Alias.new(@relation) (aliaz = Alias.new(@relation)).should == aliaz end end diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index 0a08deffb8..2688ece4a5 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -17,8 +17,8 @@ module Arel describe 'when given a', Symbol, String do it "returns the attribute with the same name, if it exists" do - @relation[:id].should == @attribute1 - @relation['id'].should == @attribute1 + check @relation[:id].should == @attribute1 + check @relation['id'].should == @attribute1 @relation[:does_not_exist].should be_nil end end @@ -180,7 +180,7 @@ module Arel describe Relation::Enumerable do it "implements enumerable" do - @relation.collect.should == @relation.session.read(@relation).collect + check @relation.collect.should == @relation.session.read(@relation).collect @relation.first.should == @relation.session.read(@relation).first end end diff --git a/spec/arel/algebra/unit/relations/table_spec.rb b/spec/arel/algebra/unit/relations/table_spec.rb index e4c4e58b75..19c1ba2bea 100644 --- a/spec/arel/algebra/unit/relations/table_spec.rb +++ b/spec/arel/algebra/unit/relations/table_spec.rb @@ -9,7 +9,7 @@ module Arel describe '[]' do describe 'when given a', Symbol do it "manufactures an attribute if the symbol names an attribute within the relation" do - @relation[:id].should == Attribute.new(@relation, :id) + check @relation[:id].should == Attribute.new(@relation, :id) @relation[:does_not_exist].should be_nil end end diff --git a/spec/arel/engines/sql/unit/predicates/binary_spec.rb b/spec/arel/engines/sql/unit/predicates/binary_spec.rb index ccf9d4ef73..783e6c6a7b 100644 --- a/spec/arel/engines/sql/unit/predicates/binary_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/binary_spec.rb @@ -2,15 +2,16 @@ require 'spec_helper' module Arel describe Binary do + class ConcreteBinary < Binary + def predicate_sql + "<=>" + end + end + before do @relation = Table.new(:users) @attribute1 = @relation[:id] @attribute2 = @relation[:name] - class ConcreteBinary < Binary - def predicate_sql - "<=>" - end - end end describe "with compound predicates" do diff --git a/spec/doubles/hash.rb b/spec/doubles/hash.rb index 32c5b98058..fd9edd34ad 100644 --- a/spec/doubles/hash.rb +++ b/spec/doubles/hash.rb @@ -3,18 +3,22 @@ class Hash to_a.sort { |(key1, value1), (key2, value2)| key1.hash <=> key2.hash } end + undef :keys def keys ordered_array.collect(&:first) end + undef :values def values ordered_array.collect { |_, v| v } end + undef :each def each(&block) ordered_array.each(&block) end + undef :shift def shift returning to_a.first do |k, v| delete(k) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index beb634fbd3..7d61fc9120 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -37,9 +37,17 @@ module AdapterGuards end end +module Check + # This is used to eliminate Ruby warnings on some RSpec assertion lines + # See: https://rspec.lighthouseapp.com/projects/5645/tickets/504 + def check(*args) + end +end + Spec::Runner.configure do |config| config.include BeLikeMatcher, HashTheSameAsMatcher, DisambiguateAttributesMatcher config.include AdapterGuards + config.include Check config.mock_with :rr config.before do Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)