Skip to content

Commit

Permalink
upgrade many canvas gems to rspec 3 syntax
Browse files Browse the repository at this point in the history
as of this commit, all canvas gems should be on rspec 3.5, and pass
without deprecation warnings.

closes CNVS-34040

test plan: specs should pass without deprecation warnings

Change-Id: I556b1a4a5aeb791c6ddd50ee35b51c513e025019
Reviewed-on: https://gerrit.instructure.com/98414
Reviewed-by: Landon Wilkins <[email protected]>
Product-Review: Landon Wilkins <[email protected]>
QA-Review: Landon Wilkins <[email protected]>
Tested-by: Jenkins
  • Loading branch information
simonista committed Dec 27, 2016
1 parent e402017 commit 359c6de
Show file tree
Hide file tree
Showing 97 changed files with 425 additions and 459 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~>1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "3.5.0"
spec.add_development_dependency "rspec", "~> 3.5.0"
end
2 changes: 1 addition & 1 deletion gems/adheres_to_policy/adheres_to_policy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "2.99.0"
spec.add_development_dependency "rspec", "~> 3.5.0"
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@
end

it "should filter policy_block through a block filter with set_policy" do
@some_class.should respond_to(:set_policy)
lambda { @some_class.set_policy(1) }.should raise_error
expect(@some_class).to respond_to(:set_policy)
expect { @some_class.set_policy(1) }.to raise_error(ArgumentError)
b = lambda { 1 }
lambda { @some_class.set_policy(&b) }.should_not raise_error
expect { @some_class.set_policy(&b) }.not_to raise_error
end

it "should use set_permissions as set_policy" do
@some_class.should respond_to(:set_permissions)
lambda { @some_class.set_permissions(1) }.should raise_error
expect(@some_class).to respond_to(:set_permissions)
expect { @some_class.set_permissions(1) }.to raise_error(ArgumentError)
b = lambda { 1 }
lambda { @some_class.set_permissions(&b) }.should_not raise_error
expect { @some_class.set_permissions(&b) }.not_to raise_error
end

it "should provide a Policy instance through policy" do
@some_class.set_policy { 1 }
@some_class.policy.should be_is_a(AdheresToPolicy::Policy)
expect(@some_class.policy).to be_is_a(AdheresToPolicy::Policy)
end

it "should continue to use the same Policy instance (an important check, since this is also a constructor)" do
@some_class.set_policy { 1 }
@some_class.policy.should eql(@some_class.policy)
expect(@some_class.policy).to eql(@some_class.policy)
end

it "should apply all given policy blocks to the Policy instance" do
Expand Down
18 changes: 9 additions & 9 deletions gems/adheres_to_policy/spec/adheres_to_policy/condition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
end

it 'evaluates the condition in the context of the object' do
object = mock
thing = mock
object = double
thing = double
expect(thing).to receive(:happened).with(object)

condition = AdheresToPolicy::Condition.new(proc {
Expand All @@ -48,9 +48,9 @@
end

it 'passes in the user and session' do
user = mock
session = mock
thing = mock
user = double
session = double
thing = double
expect(thing).to receive(:happened).with(user, session)

condition = AdheresToPolicy::Condition.new(proc { |user, session|
Expand All @@ -60,15 +60,15 @@
end

it 'works with lambdas with only one argument' do
user = mock
thing = mock
user = double
thing = double
expect(thing).to receive(:happened).with(user)

condition = AdheresToPolicy::Condition.new((lambda { |user|
thing.happened(user)
}))

condition.applies?(nil, user, mock)
condition.applies?(nil, user, double)
end
end
end
end
12 changes: 6 additions & 6 deletions gems/adheres_to_policy/spec/adheres_to_policy/policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@

describe AdheresToPolicy::Policy, "set_policy" do
it "should take a block" do
lambda {
expect {
Class.new do
extend AdheresToPolicy::ClassMethods
set_policy { 1 + 1 }
end
}.should_not raise_error
}.not_to raise_error
end

it "should allow multiple calls" do
lambda {
expect {
Class.new do
extend AdheresToPolicy::ClassMethods

3.times do
set_policy { 1 + 1 }
end
end
}.should_not raise_error
}.not_to raise_error
end

context "available_rights" do
Expand All @@ -60,8 +60,8 @@

describe '#add_rights' do
it 'should add rights to parents' do
right = mock
condition = mock
right = double
condition = double
parent = AdheresToPolicy::Policy.new(nil, nil)
policy = AdheresToPolicy::Policy.new(parent, nil)

Expand Down
3 changes: 1 addition & 2 deletions gems/adheres_to_policy/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
require 'adheres_to_policy'

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.order = 'random'
Expand All @@ -31,4 +30,4 @@ module Rails
def self.cache
@cache ||= ActiveSupport::Cache::MemoryStore.new
end
end
end
3 changes: 1 addition & 2 deletions gems/bookmarked_collection/bookmarked_collection.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "2.99.0"
spec.add_development_dependency "rspec", "~> 3.5.0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "byebug"

end
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ def self.restrict_scope(scope, pager)
end

it "should return a WrapProxy" do
BookmarkedCollection.wrap(IDBookmarker, @scope).should be_a(PaginatedCollection::Proxy)
expect(BookmarkedCollection.wrap(IDBookmarker, @scope)).to be_a(PaginatedCollection::Proxy)
end

it "should use the provided scope when executing pagination" do
collection = BookmarkedCollection.wrap(IDBookmarker, @scope)
collection.paginate(:per_page => 1).should == [@scope.first]
expect(collection.paginate(:per_page => 1)).to eq([@scope.first])
end

it "should use the bookmarker's bookmark generator to produce bookmarks" do
bookmark = double
allow(IDBookmarker).to receive(:bookmark_for) { bookmark }

collection = BookmarkedCollection.wrap(IDBookmarker, @scope)
collection.paginate(:per_page => 1).next_bookmark.should == bookmark
expect(collection.paginate(:per_page => 1).next_bookmark).to eq(bookmark)
end

it "should use the bookmarker's bookmark applicator to restrict by bookmark" do
Expand All @@ -88,7 +88,7 @@ def self.restrict_scope(scope, pager)
allow(IDBookmarker).to receive(:restrict_scope) { bookmarked_scope }

collection = BookmarkedCollection.wrap(IDBookmarker, @scope)
collection.paginate(:per_page => 1).should == [bookmarked_scope.first]
expect(collection.paginate(:per_page => 1)).to eq([bookmarked_scope.first])
end

it "should apply any restriction block given to the scope" do
Expand All @@ -99,7 +99,7 @@ def self.restrict_scope(scope, pager)
scope.where(:name => course.name)
end

collection.paginate(:per_page => 1).should == [course]
expect(collection.paginate(:per_page => 1)).to eq([course])
end
end

Expand All @@ -126,27 +126,27 @@ def self.restrict_scope(scope, pager)
end

it "should return a merge proxy" do
@collection.should be_a(BookmarkedCollection::MergeProxy)
expect(@collection).to be_a(BookmarkedCollection::MergeProxy)
end

it "should merge the given collections" do
@collection.paginate(:per_page => 2).should == [@created_course1, @deleted_course1]
expect(@collection.paginate(:per_page => 2)).to eq([@created_course1, @deleted_course1])
end

it "should have a next page when there's a non-exhausted collection" do
@collection.paginate(:per_page => 3).next_page.should_not be_nil
expect(@collection.paginate(:per_page => 3).next_page).not_to be_nil
end

it "should not have a next page when all collections are exhausted" do
@collection.paginate(:per_page => 4).next_page.should be_nil
expect(@collection.paginate(:per_page => 4).next_page).to be_nil
end

it "should pick up in the middle of a collection" do
page = @collection.paginate(:per_page => 1)
page.should == [@created_course1]
page.next_bookmark.should_not be_nil
expect(page).to eq([@created_course1])
expect(page.next_bookmark).not_to be_nil

@collection.paginate(:page => page.next_page, :per_page => 2).should == [@deleted_course1, @created_course2]
expect(@collection.paginate(:page => page.next_page, :per_page => 2)).to eq([@deleted_course1, @created_course2])
end

context "with a merge proc" do
Expand All @@ -168,7 +168,7 @@ def self.restrict_scope(scope, pager)
end

it "should collapse duplicates" do
@collection.paginate(:per_page => 2).should == [@created_course]
expect(@collection.paginate(:per_page => 2)).to eq([@created_course])
end
end

Expand All @@ -191,17 +191,17 @@ def self.restrict_scope(scope, pager)
end

it "should sort the ties by collection" do
@collection.paginate(:per_page => 2).should == [@created_course, @deleted_course]
expect(@collection.paginate(:per_page => 2)).to eq([@created_course, @deleted_course])
end

it "should pick up at the right place when a page break splits the tie" do
page = @collection.paginate(:per_page => 1)
page.should == [@created_course]
page.next_bookmark.should_not be_nil
expect(page).to eq([@created_course])
expect(page.next_bookmark).not_to be_nil

page = @collection.paginate(:page => page.next_page, :per_page => 1)
page.should == [@deleted_course]
page.next_bookmark.should be_nil
expect(page).to eq([@deleted_course])
expect(page.next_bookmark).to be_nil
end
end
end
Expand Down Expand Up @@ -229,39 +229,39 @@ def self.restrict_scope(scope, pager)
end

it "should return a concat proxy" do
@collection.should be_a(BookmarkedCollection::ConcatProxy)
expect(@collection).to be_a(BookmarkedCollection::ConcatProxy)
end

it "should concatenate the given collections" do
@collection.paginate(:per_page => 3).should == [@created_course1, @created_course2, @deleted_course1]
expect(@collection.paginate(:per_page => 3)).to eq([@created_course1, @created_course2, @deleted_course1])
end

it "should have a next page when there's a non-exhausted collection" do
@collection.paginate(:per_page => 3).next_page.should_not be_nil
expect(@collection.paginate(:per_page => 3).next_page).not_to be_nil
end

it "should have a next page on the border between an exhausted collection and a non-exhausted collection" do
@collection.paginate(:per_page => 2).next_page.should_not be_nil
expect(@collection.paginate(:per_page => 2).next_page).not_to be_nil
end

it "should not have a next page when all collections are exhausted" do
@collection.paginate(:per_page => 4).next_page.should be_nil
expect(@collection.paginate(:per_page => 4).next_page).to be_nil
end

it "should pick up in the middle of a collection" do
page = @collection.paginate(:per_page => 1)
page.should == [@created_course1]
page.next_bookmark.should_not be_nil
expect(page).to eq([@created_course1])
expect(page.next_bookmark).not_to be_nil

@collection.paginate(:page => page.next_page, :per_page => 2).should == [@created_course2, @deleted_course1]
expect(@collection.paginate(:page => page.next_page, :per_page => 2)).to eq([@created_course2, @deleted_course1])
end

it "should pick up from a break between collections" do
page = @collection.paginate(:per_page => 2)
page.should == [@created_course1, @created_course2]
page.next_bookmark.should_not be_nil
expect(page).to eq([@created_course1, @created_course2])
expect(page.next_bookmark).not_to be_nil

@collection.paginate(:page => page.next_page, :per_page => 2).should == [@deleted_course1, @deleted_course2]
expect(@collection.paginate(:page => page.next_page, :per_page => 2)).to eq([@deleted_course1, @deleted_course2])
end

it "doesn't get confused by subcollections that don't respect per_page" do
Expand All @@ -279,8 +279,8 @@ def self.restrict_scope(scope, pager)
['created', created_collection],
['deleted', @deleted_collection]
)
created_collection.paginate(per_page: 3).should == [@created_course1]
@collection.paginate(per_page: 3).should == [@created_course1, @created_course2, @deleted_course1]
expect(created_collection.paginate(per_page: 3)).to eq([@created_course1])
expect(@collection.paginate(per_page: 3)).to eq([@created_course1, @created_course2, @deleted_course1])
end

it "efficiently has a next page that coincides with a partial read" do
Expand All @@ -300,7 +300,7 @@ def self.restrict_scope(scope, pager)
)

expect(@deleted_collection).to receive(:execute_pager).never
@collection.paginate(per_page: 1).next_page.should_not be_nil
expect(@collection.paginate(per_page: 1).next_page).not_to be_nil
end


Expand Down Expand Up @@ -346,12 +346,12 @@ def self.restrict_scope(scope, pager)
)

page = @collection.paginate(:per_page => 4)
page.should == [@user1, @user2, @created_course1, @deleted_course1]
page.next_page.should_not be_nil
expect(page).to eq([@user1, @user2, @created_course1, @deleted_course1])
expect(page.next_page).not_to be_nil

page = @collection.paginate(:page => page.next_page, :per_page => 2)
page.should == [@created_course2, @deleted_course2]
page.next_page.should be_nil
expect(page).to eq([@created_course2, @deleted_course2])
expect(page.next_page).to be_nil
end

it "should handle merge(A, merge(B, C))" do
Expand All @@ -371,12 +371,12 @@ def self.restrict_scope(scope, pager)
)

page = @collection.paginate(:per_page => 3)
page.should == [@created_course1, @created_course2, @user1]
page.next_page.should_not be_nil
expect(page).to eq([@created_course1, @created_course2, @user1])
expect(page.next_page).not_to be_nil

page = @collection.paginate(:page => page.next_page, :per_page => 3)
page.should == [@user2, @deleted_course1, @deleted_course2]
page.next_page.should be_nil
expect(page).to eq([@user2, @deleted_course1, @deleted_course2])
expect(page.next_page).to be_nil
end

it "should handle concat(A, concat(B, C))" do
Expand All @@ -393,12 +393,12 @@ def self.restrict_scope(scope, pager)
['courses', @course_collection])

page = @collection.paginate(:per_page => 3)
page.should == [@user1, @user2, @created_course1]
page.next_page.should_not be_nil
expect(page).to eq([@user1, @user2, @created_course1])
expect(page.next_page).not_to be_nil

page = @collection.paginate(:page => page.next_page, :per_page => 3)
page.should == [@created_course2, @deleted_course1, @deleted_course2]
page.next_page.should be_nil
expect(page).to eq([@created_course2, @deleted_course1, @deleted_course2])
expect(page.next_page).to be_nil
end

it "should not allow merge(A, concat(B, C))" do
Expand Down
Loading

0 comments on commit 359c6de

Please sign in to comment.