spec/authority/authorizer_spec.rb in authority-2.2.0 vs spec/authority/authorizer_spec.rb in authority-2.3.0
- old
+ new
@@ -1,45 +1,45 @@
require 'spec_helper'
-require 'support/example_model'
-require 'support/user'
+require 'support/example_classes'
describe Authority::Authorizer do
- before :each do
- @example_model = ExampleModel.new
- @authorizer = @example_model.authorizer
- @user = User.new
- end
+ let(:model_instance) { ExampleResource.new }
+ let(:authorizer) { model_instance.authorizer }
+ let(:user) { ExampleUser.new }
- it "should take a resource instance in its initializer" do
- @authorizer.resource.should eq(@example_model)
+ it "takes a resource instance in its initializer" do
+ expect(authorizer.resource).to eq(model_instance)
end
describe "instance methods" do
Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
- it "should respond to `#{method_name}`" do
- @authorizer.should respond_to(method_name)
+ it "responds to `#{method_name}`" do
+ expect(authorizer).to respond_to(method_name)
end
+ describe "#{method_name}" do
- describe "if given an options hash" do
+ context "when given an options hash" do
- it "should delegate `#{method_name}` to the corresponding class method, passing the options" do
- @authorizer.class.should_receive(method_name).with(@user, :under => 'God')
- @authorizer.send(method_name, @user, :under => 'God')
+ it "delegates `#{method_name}` to the corresponding class method, passing the options" do
+ authorizer.class.should_receive(method_name).with(user, :under => 'God')
+ authorizer.send(method_name, user, :under => 'God')
+ end
+
end
- end
+ context "when not given an options hash" do
- describe "if not given an options hash" do
+ it "delegates `#{method_name}` to the corresponding class method, passing no options" do
+ authorizer.class.should_receive(method_name).with(user)
+ authorizer.send(method_name, user)
+ end
- it "should delegate `#{method_name}` to the corresponding class method, passing no options" do
- @authorizer.class.should_receive(method_name).with(@user)
- @authorizer.send(method_name, @user)
end
end
end
@@ -49,50 +49,54 @@
describe "class methods" do
Authority.adjectives.each do |adjective|
method_name = "#{adjective}_by?"
- it "should respond to `#{method_name}`" do
- Authority::Authorizer.should respond_to(method_name)
+ it "responds to `#{method_name}`" do
+ expect(Authority::Authorizer).to respond_to(method_name)
end
- describe "if given an options hash" do
+ describe "#{method_name}" do
- it "should delegate `#{method_name}` to the authorizer's `default` method, passing the options" do
- able = method_name.sub('_by?', '').to_sym
- Authority::Authorizer.should_receive(:default).with(able, @user, :with => 'gusto')
- Authority::Authorizer.send(method_name, @user, :with => 'gusto')
+ context "when given an options hash" do
+
+ it "delegates `#{method_name}` to the authorizer's `default` method, passing the options" do
+ able = method_name.sub('_by?', '').to_sym
+ Authority::Authorizer.should_receive(:default).with(able, user, :with => 'gusto')
+ Authority::Authorizer.send(method_name, user, :with => 'gusto')
+ end
+
end
- end
+ context "when not given an options hash" do
- describe "if not given an options hash" do
+ it "delegates `#{method_name}` to the authorizer's `default` method, passing no options" do
+ able = method_name.sub('_by?', '').to_sym
+ Authority::Authorizer.should_receive(:default).with(able, user)
+ Authority::Authorizer.send(method_name, user)
+ end
- it "should delegate `#{method_name}` to the authorizer's `default` method, passing no options" do
- able = method_name.sub('_by?', '').to_sym
- Authority::Authorizer.should_receive(:default).with(able, @user)
- Authority::Authorizer.send(method_name, @user)
end
end
end
end
describe "the default method" do
- describe "if given an options hash" do
+ context "when given an options hash" do
- it "should return false" do
- Authority::Authorizer.default(:implodable, @user, {:for => "my_object"}).should be_false
+ it "returns false" do
+ expect(Authority::Authorizer.default(:implodable, user, {:for => "my_object"})).to be_false
end
end
- describe "if not given an options hash" do
+ context "when not given an options hash" do
- it "should return false" do
- Authority::Authorizer.default(:implodable, @user).should be_false
+ it "returns false" do
+ expect(Authority::Authorizer.default(:implodable, user)).to be_false
end
end
end