spec/hexx/coercible_spec.rb in hexx-6.0.2 vs spec/hexx/coercible_spec.rb in hexx-6.0.3
- old
+ new
@@ -23,15 +23,50 @@
# Run tests
# ==========================================================================
describe ".attr_coerced" do
- before { test_model.send :attr_coerced, :name, type: test_coercion }
- subject { test_model.new }
+ context "when the name is neither type nor symbol" do
- it "coerces an attribute with given type" do
- subject.name = "some name"
- expect(subject.name).to be_kind_of test_coercion
+ it "fails with TypeError" do
+ expect { test_model.send :attr_coerced, 1, type: test_coercion }
+ .to raise_error(TypeError)
+ end
+ end
+
+ context "when the name is empty" do
+
+ it "fails with ArgumentError" do
+ expect { test_model.send :attr_coerced, "", type: test_coercion }
+ .to raise_error(ArgumentError)
+ end
+ end
+
+ context "when no type is set" do
+
+ it "fails with ArgumentError" do
+ expect { test_model.send :attr_coerced, :name }
+ .to raise_error(ArgumentError)
+ end
+ end
+
+ context "when a type is not a class" do
+
+ it "fails with TypeError" do
+ expect { test_model.send :attr_coerced, :name, type: test_module }
+ .to raise_error(TypeError)
+ end
+ end
+
+ context "with valid arguments" do
+
+ before { test_model.send :attr_coerced, :name, type: test_coercion }
+ subject { test_model.new }
+
+ it "coerces an attribute with given type" do
+ subject.name = "some name"
+ expect(subject.name).to be_kind_of test_coercion
+ end
end
end
end
end