Skip to content

Commit

Permalink
Update RSpec to 2.99
Browse files Browse the repository at this point in the history
  • Loading branch information
take-five committed Jul 2, 2014
1 parent aa18b69 commit 49d35ac
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion acts_as_ordered_tree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rake', '~> 10.1.1'
s.add_development_dependency 'bundler', '~> 1.5'
s.add_development_dependency 'rspec', '~> 2.14.1'
s.add_development_dependency 'rspec', '~> 2.99.0'
s.add_development_dependency 'database_cleaner', '~> 1.2.0'
s.add_development_dependency 'factory_girl', '~> 4.4.0'
s.add_development_dependency 'appraisal', '>= 1.0.0.beta3'
Expand Down
28 changes: 18 additions & 10 deletions spec/acts_as_ordered_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@
context 'given a persistent root node' do
subject { create :default }

its(:level) { should eq 0 }
it { expect(subject.level).to eq 0 }
end

context 'given a new root record' do
subject { build :default }

its(:level) { should eq 0 }
it { expect(subject.level).to eq 0 }
end

context 'given a persistent node with parent' do
let(:root) { create :default }
subject { create :default, :parent => root }
its(:level) { should eq 1 }

it { expect(subject.level).to eq 1 }
end

context 'given a new node with parent' do
let(:root) { create :default }
subject { build :default, :parent => root }
its(:level) { should eq 1 }

it { expect(subject.level).to eq 1 }
end

context 'a model without depth column' do
Expand Down Expand Up @@ -108,12 +110,12 @@
expect(root1.descendants.reload).not_to include orphan
end
it 'should not allow to move records between scopes' do
expect(child2.move_to_child_of(root1)).to be_false
expect(child2).to have_at_least(1).error_on(:parent)
expect(child2.move_to_child_of(root1)).to be false
expect(child2.errors_on(:parent).size).to be >= 1
end
it 'should not allow to change scope' do
child2.parent = root1
expect(child2).to have_at_least(1).error_on(:parent)
expect(child2.errors_on(:parent).size).to be >= 1
end
it 'should not allow to add scoped record to children collection' do
root1.children << child2
Expand All @@ -132,19 +134,25 @@
context "given self as parent" do
before { root.parent = root }

it { should have_at_least(1).error_on(:parent) }
it 'has at least 1 error_on' do
expect(subject.error_on(:parent).size).to be >= 1
end
end

context "given child as parent" do
before { root.parent = child }

it { should have_at_least(1).error_on(:parent) }
it 'has at least 1 error_on' do
expect(subject.error_on(:parent).size).to be >= 1
end
end

context "given grandchild as parent" do
before { root.parent = grandchild }

it { should have_at_least(1).error_on(:parent) }
it 'has at least 1 error_on' do
expect(subject.error_on(:parent).size).to be >= 1
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/adapters/shared.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

shared_examples 'ActsAsOrderedTree adapter' do |adapter_class, model, attrs = {}|
context model do
context model.to_s do
tree :factory => model, :attributes => attrs do
root {
child_1 {
Expand Down Expand Up @@ -108,7 +108,7 @@

it 'updates descendants' do
relation.update_all(:name => 'x')
expect(relation.all? { |r| r.reload.name == 'x' }).to be_true
expect(relation.all? { |r| r.reload.name == 'x' }).to be true

adapter.descendants(child_1).update_all(:name => 'y')
adapter.descendants(child_2).update_all(:name => 'z')
Expand Down
2 changes: 2 additions & 0 deletions spec/callbacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def run_callback(kind, *args)
end

matcher :trigger_callback do |*callbacks, &block|
supports_block_expectations

match_for_should do |proc|
@with ||= nil
Class1.triggered_callbacks = []
Expand Down
2 changes: 1 addition & 1 deletion spec/inheritance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ConcreteCategoryWithScope < BaseCategory
it { expect(node.children).to be_of klass }

it 'applies class default scope to #children' do
expect(node.children).to have(1).item
expect(node.children.size).to eq 1
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/node/movements/move_to_child_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end

context 'moving to child of self' do
it { expect(child_3.move_to_child_of(child_3)).to be_false }
it { expect(child_3.move_to_child_of(child_3)).to be false }

it 'does not move node' do
expect {
Expand All @@ -55,7 +55,7 @@
end

context 'moving to child of descendant' do
it { expect(root.move_to_child_of(child_1)).to be_false }
it { expect(root.move_to_child_of(child_1)).to be false }

it 'does node move node' do
expect {
Expand Down Expand Up @@ -113,9 +113,9 @@
end

context 'moving to non-existent ID' do
before { child_3.stub(:valid?).and_return(false) }
before { allow(child_3).to receive(:valid?).and_return(false) }

it { expect(child_3.move_to_child_of(-1)).to be_false }
it { expect(child_3.move_to_child_of(-1)).to be false }

it 'does not move node' do
expect {
Expand Down
16 changes: 8 additions & 8 deletions spec/node/predicates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@
before { child.class.where(:id => child.id).update_all(['scope_type = ?', 'b']) }

context 'when parent association is cached and cache is stale' do
it { expect(root.is_ancestor_of?(child)).to be_false }
it { expect(root.is_or_is_ancestor_of?(child)).to be_false }
it { expect(child.is_descendant_of?(root)).to be_false }
it { expect(child.is_or_is_descendant_of?(root)).to be_false }
it { expect(root.is_ancestor_of?(child)).to be false }
it { expect(root.is_or_is_ancestor_of?(child)).to be false }
it { expect(child.is_descendant_of?(root)).to be false }
it { expect(child.is_or_is_descendant_of?(root)).to be false }
end

context 'when parent association is not loaded' do
before { child.reload }

it { expect(root.is_ancestor_of?(child)).to be_false }
it { expect(root.is_or_is_ancestor_of?(child)).to be_false }
it { expect(child.is_descendant_of?(root)).to be_false }
it { expect(child.is_or_is_descendant_of?(root)).to be_false }
it { expect(root.is_ancestor_of?(child)).to be false }
it { expect(root.is_or_is_ancestor_of?(child)).to be false }
it { expect(child.is_descendant_of?(root)).to be false }
it { expect(child.is_or_is_descendant_of?(root)).to be false }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'bundler/setup'

require 'rspec'
require 'rspec-expectations'
require 'rspec/expectations'

if ENV['COVERAGE'].to_i.nonzero?
begin
Expand Down
4 changes: 4 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def failure_message_for_should_not
failure_message_for_should(true)
end

def supports_block_expectations?
true
end

private
def record_queries
@queries = []
Expand Down
2 changes: 1 addition & 1 deletion spec/support/tree_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def expect_tree_to_match(&block)
end

def ast
@ast ||= TreeFactory::Parser.new.parse(matcher_execution_context, &@expected_tree)
@ast ||= TreeFactory::Parser.new.parse(self, &@expected_tree)
end

def attributes_to_expose
Expand Down
10 changes: 5 additions & 5 deletions spec/tree/children_association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe ActsAsOrderedTree::Tree::ChildrenAssociation, :transactional do
shared_examples 'ChildrenAssociation' do |model|
describe model do
describe model.to_s do
tree :factory => model do
root {
child_1
Expand All @@ -22,7 +22,7 @@
end

describe 'loading association' do
it { expect(root.children).to have(3).items }
it { expect(root.children.size).to eq 3 }
it { expect(root.children).to eq [child_1, child_2, child_3] }

it { expect{root.children.to_a}.to query_database(/ORDER BY .*position/) }
Expand All @@ -34,7 +34,7 @@

it { expect(relation).to eq [root, child_1, child_2, child_3] }
it { expect(first.children).to be_loaded }
it { expect(first.children).to have(3).items }
it { expect(first.children.size).to eq 3 }
end

describe 'preloading association' do
Expand All @@ -43,7 +43,7 @@

it { expect(relation).to eq [root, child_1, child_2, child_3] }
it { expect(first.children).to be_loaded }
it { expect(first.children).to have(3).items }
it { expect(first.children.size).to eq 3 }
end

describe 'preloading association (via includes method)' do
Expand All @@ -52,7 +52,7 @@

it { expect(relation).to eq [root, child_1, child_2, child_3] }
it { expect(first.children).to be_loaded }
it { expect(first.children).to have(3).items }
it { expect(first.children.size).to eq 3 }
end

describe 'extensions' do
Expand Down
2 changes: 1 addition & 1 deletion spec/tree/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe ActsAsOrderedTree::Tree::Scopes, :transactional do
shared_examples 'ActsAsOrderedTree scopes' do |model, attrs = {}|
describe model do
describe model.to_s do
tree :factory => model, :attributes => attrs do
root_1 {
child_1 {
Expand Down

0 comments on commit 49d35ac

Please sign in to comment.