Permalink
Browse files

Banish the explicit use of subject in specs

  • Loading branch information...
1 parent 39c4bc7 commit e752a0855ce9b39d6a2ca039548c4adc01800bb8 @cgriego committed Dec 31, 2012
Showing with 425 additions and 413 deletions.
  1. +1 −1 active_attr.gemspec
  2. +12 −12 spec/functional/active_attr/attribute_defaults_spec.rb
  3. +12 −12 spec/functional/active_attr/attributes_spec.rb
  4. +3 −3 spec/functional/active_attr/chainable_initialization_spec.rb
  5. +0 −2 spec/functional/active_attr/mass_assignment_security_spec.rb
  6. +66 −66 spec/functional/active_attr/matchers/have_attribute_matcher_spec.rb
  7. +22 −19 spec/functional/active_attr/model_spec.rb
  8. +5 −5 spec/functional/active_attr/serialization_spec.rb
  9. +45 −45 spec/functional/active_attr/typecasted_attributes_spec.rb
  10. +12 −12 spec/support/mass_assignment_shared_examples.rb
  11. +6 −6 spec/unit/active_attr/attribute_defaults_spec.rb
  12. +6 −6 spec/unit/active_attr/attribute_definition_spec.rb
  13. +38 −38 spec/unit/active_attr/attributes_spec.rb
  14. +16 −16 spec/unit/active_attr/logger_spec.rb
  15. +0 −2 spec/unit/active_attr/mass_assignment_security_spec.rb
  16. +1 −1 spec/unit/active_attr/mass_assignment_spec.rb
  17. +3 −4 spec/unit/active_attr/matchers_spec.rb
  18. +75 −75 spec/unit/active_attr/query_attributes_spec.rb
  19. +10 −10 spec/unit/active_attr/typecasted_attributes_spec.rb
  20. +9 −7 spec/unit/active_attr/typecasting/big_decimal_typecaster_spec.rb
  21. +27 −25 spec/unit/active_attr/typecasting/boolean_typecaster_spec.rb
  22. +12 −10 spec/unit/active_attr/typecasting/date_time_typecaster_spec.rb
  23. +14 −12 spec/unit/active_attr/typecasting/date_typecaster_spec.rb
  24. +6 −4 spec/unit/active_attr/typecasting/float_typecaster_spec.rb
  25. +8 −6 spec/unit/active_attr/typecasting/integer_typecaster_spec.rb
  26. +3 −1 spec/unit/active_attr/typecasting/object_typecaster_spec.rb
  27. +5 −3 spec/unit/active_attr/typecasting/string_typecaster_spec.rb
  28. +3 −5 spec/unit/active_attr/typecasting_spec.rb
  29. +5 −5 spec/unit/active_attr/version_spec.rb
View
@@ -21,6 +21,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "bundler", "~> 1.0"
gem.add_development_dependency "factory_girl", ">= 2.2", "< 4.0"
gem.add_development_dependency "rake", "~> 0.9.0"
- gem.add_development_dependency "rspec", "~> 2.6"
+ gem.add_development_dependency "rspec", "~> 2.11"
gem.add_development_dependency "tzinfo", "~> 0.3.29"
end
@@ -6,7 +6,7 @@
module ActiveAttr
describe AttributeDefaults do
- subject { model_class.new }
+ subject(:model) { model_class.new }
let :model_class do
Class.new.tap do |model_class|
@@ -20,20 +20,20 @@ module ActiveAttr
before { model_class.attribute :first_name, :default => "John" }
it "the attribute getter returns the string by default" do
- subject.first_name.should == "John"
+ model.first_name.should == "John"
end
it "#attributes includes the default attributes" do
- subject.attributes["first_name"].should == "John"
+ model.attributes["first_name"].should == "John"
end
it "#read_attribute returns the string by default" do
- subject.read_attribute("first_name").should == "John"
+ model.read_attribute("first_name").should == "John"
end
it "assigning nil sets nil as the attribute value" do
- subject.first_name = nil
- subject.first_name.should be_nil
+ model.first_name = nil
+ model.first_name.should be_nil
end
it "mutating the default value does not mutate the attribute definition" do
@@ -46,35 +46,35 @@ module ActiveAttr
before { model_class.attribute :admin, :default => false }
it "the attribute getter returns false by default" do
- subject.admin.should == false
+ model.admin.should == false
end
end
context "an attribute with a default of true" do
before { model_class.attribute :remember_me, :default => true }
it "the attribute getter returns true by default" do
- subject.remember_me.should == true
+ model.remember_me.should == true
end
end
context "an attribute with a default empty Array" do
before { model_class.attribute :roles, :default => [] }
it "the attribute getter returns an empty array by default" do
- subject.roles.should == []
+ model.roles.should == []
end
end
context "an attribute with a dynamic Time.now default" do
before { model_class.attribute :created_at, :default => lambda { Time.now } }
it "the attribute getter returns a Time instance" do
- subject.created_at.should be_a_kind_of Time
+ model.created_at.should be_a_kind_of Time
end
it "the attribute default is only evaulated once per instance" do
- subject.created_at.should == subject.created_at
+ model.created_at.should == model.created_at
end
it "the attribute default is different per instance" do
@@ -86,7 +86,7 @@ module ActiveAttr
before { model_class.attribute :id, :default => lambda { object_id } }
it "the attribute getter returns the default based on the instance" do
- subject.id.should == subject.object_id
+ model.id.should == model.object_id
end
end
@@ -23,10 +23,10 @@ def id
end
end
- subject { model_class.new }
+ subject(:model) { model_class.new }
it "correctly defines methods for the attributes instead of relying on method_missing" do
- subject.id.should be_nil
+ model.id.should be_nil
end
end
@@ -95,7 +95,7 @@ def id
context "serializing a model" do
let(:first_name) { "Chris" }
- let :instance do
+ let :model do
model_class.new.tap do |model|
model.first_name = first_name
end
@@ -129,34 +129,34 @@ def self.name
end
it "includes unassigned, defined attributes" do
- subject.keys.should include("last_name")
- subject["last_name"].should be_nil
+ serialized_model.keys.should include("last_name")
+ serialized_model["last_name"].should be_nil
end
end
describe "#as_json" do
- subject { instance.as_json["person"] }
+ subject(:serialized_model) { model.as_json["person"] }
include_examples "serialization method"
end
describe "#serializable_hash" do
- subject { instance.serializable_hash }
+ subject(:serialized_model) { model.serializable_hash }
include_examples "serialization method"
end
describe "#to_json" do
- subject { ActiveSupport::JSON.decode(instance.to_json)["person"] }
+ subject(:serialized_model) { ActiveSupport::JSON.decode(model.to_json)["person"] }
include_examples "serialization method"
end
describe "#to_xml" do
- subject { Hash.from_xml(instance.to_xml)["person"] }
+ subject(:serialized_model) { Hash.from_xml(model.to_xml)["person"] }
include_examples "serialization method"
end
end
context "building with FactoryGirl" do
- subject { FactoryGirl.build(:person) }
+ subject(:model) { FactoryGirl.build(:person) }
before do
Object.const_set("Person", model_class)
@@ -187,8 +187,8 @@ def self.name
end
it "sets the attributes" do
- subject.first_name.should eq "Chris"
- subject.last_name.should == "Griego"
+ model.first_name.should eq "Chris"
+ model.last_name.should == "Griego"
end
end
@@ -4,12 +4,12 @@
module ActiveAttr
describe ChainableInitialization do
- subject { model_class.new("arg") }
+ subject(:model) { model_class.new("arg") }
shared_examples "chained initialization" do
describe "#initialize" do
- it { expect { subject }.not_to raise_error }
- it { subject.initialized?.should be_true }
+ it { expect { model }.not_to raise_error }
+ it { model.initialized?.should be_true }
end
end
@@ -4,8 +4,6 @@
module ActiveAttr
describe MassAssignmentSecurity, :mass_assignment do
context "integrating with strong_parameters", :active_model_version => "~> 3.2.0" do
- subject { model_class }
-
before do
require "strong_parameters"
Oops, something went wrong.

0 comments on commit e752a08

Please sign in to comment.