Permalink
Browse files

More spec cleanup

  • Loading branch information...
1 parent e65b12e commit 864390e9c801fdfc5ab9eb564e760767209fbc82 @nathanl committed Dec 8, 2012
@@ -4,14 +4,12 @@
describe Authority::Authorizer do
- before :each do
- @example_model = ExampleModel.new
- @authorizer = @example_model.authorizer
- @user = User.new
- end
+ let(:model_instance) { ExampleModel.new }
+ let(:authorizer) { model_instance.authorizer }
+ let(:user) { User.new }
it "takes a resource instance in its initializer" do
- expect(@authorizer.resource).to eq(@example_model)
+ expect(authorizer.resource).to eq(model_instance)
end
describe "instance methods" do
@@ -20,25 +18,25 @@
method_name = "#{adjective}_by?"
it "responds to `#{method_name}`" do
- expect(@authorizer).to respond_to(method_name)
+ expect(authorizer).to respond_to(method_name)
end
describe "#{method_name}" do
context "when given an options hash" do
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')
+ authorizer.class.should_receive(method_name).with(user, :under => 'God')
+ authorizer.send(method_name, user, :under => 'God')
end
end
context "when 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)
+ authorizer.class.should_receive(method_name).with(user)
+ authorizer.send(method_name, user)
end
end
@@ -64,8 +62,8 @@
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')
+ Authority::Authorizer.should_receive(:default).with(able, user, :with => 'gusto')
+ Authority::Authorizer.send(method_name, user, :with => 'gusto')
end
end
@@ -74,8 +72,8 @@
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)
+ Authority::Authorizer.should_receive(:default).with(able, user)
+ Authority::Authorizer.send(method_name, user)
end
end
@@ -91,14 +89,14 @@
context "when given an options hash" do
it "returns false" do
- expect(Authority::Authorizer.default(:implodable, @user, {:for => "my_object"})).to be_false
+ expect(Authority::Authorizer.default(:implodable, user, {:for => "my_object"})).to be_false
end
end
context "when not given an options hash" do
it "returns false" do
- expect(Authority::Authorizer.default(:implodable, @user)).to be_false
+ expect(Authority::Authorizer.default(:implodable, user)).to be_false
end
end
@@ -16,8 +16,8 @@
it "logs to standard error by default" do
Authority.instance_variable_set :@configuration, nil
null = File.exists?('/dev/null') ? '/dev/null' : 'NUL:' # Allow for Windows
- @logger = Logger.new(null)
- Logger.should_receive(:new).with(STDERR).and_return(@logger)
+ logger = Logger.new(null)
+ Logger.should_receive(:new).with(STDERR).and_return(logger)
Authority.configure
Authority.configuration.logger
end
@@ -42,9 +42,10 @@
describe "instance methods" do
+ let!(:authorizer_instance) { ExampleModel.authorizer.new(model_instance) }
+
before :each do
- @authorizer_instance = ExampleModel.authorizer.new(model_instance)
- ExampleModel.authorizer.stub(:new).and_return(@authorizer_instance)
+ ExampleModel.authorizer.stub(:new).and_return(authorizer_instance)
end
Authority.verbs.each do |verb|
@@ -57,7 +58,7 @@
describe "if given an options hash" do
it "delegates `#{adjective_method}` to a new authorizer instance, passing the options" do
- @authorizer_instance.should_receive(adjective_method).with(user, :consistency => 'mushy')
+ authorizer_instance.should_receive(adjective_method).with(user, :consistency => 'mushy')
user.send(verb_method, model_instance, :consistency => 'mushy')
end
@@ -66,7 +67,7 @@
describe "if not given an options hash" do
it "delegates `#{adjective_method}` to a new authorizer instance, passing no options" do
- @authorizer_instance.should_receive(adjective_method).with(user)
+ authorizer_instance.should_receive(adjective_method).with(user)
user.send(verb_method, model_instance)
end
@@ -4,34 +4,32 @@
describe Authority::UserAbilities do
- before :each do
- @example_model = ExampleModel.new
- @user = User.new
- end
+ let(:model_instance) { ExampleModel.new }
+ let(:user) { User.new }
describe "using `can_{verb}?` methods to check permissions on a resource" do
Authority.verbs.each do |verb|
method_name = "can_#{verb}?"
it "defines the `#{method_name}` method" do
- expect(@user).to respond_to(method_name)
+ expect(user).to respond_to(method_name)
end
describe "if given options" do
it "delegates the authorization check to the resource, passing the options" do
- @example_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user, :size => 'wee')
- @user.send(method_name, @example_model, :size => 'wee')
+ model_instance.should_receive("#{Authority.abilities[verb]}_by?").with(user, :size => 'wee')
+ user.send(method_name, model_instance, :size => 'wee')
end
end
describe "if not given options" do
it "delegates the authorization check to the resource, passing no options" do
- @example_model.should_receive("#{Authority.abilities[verb]}_by?").with(@user)
- @user.send(method_name, @example_model)
+ model_instance.should_receive("#{Authority.abilities[verb]}_by?").with(user)
+ user.send(method_name, model_instance)
end
end
@@ -43,8 +41,8 @@
describe "using `can?` for non-resource-specific checks" do
it "checks with ApplicationAuthorizer" do
- ApplicationAuthorizer.should_receive(:can_mimic_lemurs?).with(@user)
- @user.can?(:mimic_lemurs)
+ ApplicationAuthorizer.should_receive(:can_mimic_lemurs?).with(user)
+ user.can?(:mimic_lemurs)
end
end

0 comments on commit 864390e

Please sign in to comment.