Last active
June 8, 2017 11:11
-
-
Save CharlieHawker/e466dc88c0b2875e02c8e9f04757dab8 to your computer and use it in GitHub Desktop.
Revisions
-
CharlieHawker revised this gist
Jun 8, 2017 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,16 +5,12 @@ module DirectAssignmentMatchers match do |object| !DirectAssignmentMatchers::public_assign(object, attribute) end end RSpec::Matchers.define :allow_direct_assignment_of do |attribute| match do |object| !!DirectAssignmentMatchers::public_assign(object, attribute) end end private -
CharlieHawker created this gist
Jun 8, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ module DirectAssignmentMatchers require 'rspec/expectations' RSpec::Matchers.define :prevent_direct_assignment_of do |attribute| match do |object| !DirectAssignmentMatchers::public_assign(object, attribute) end diffable end RSpec::Matchers.define :allow_direct_assignment_of do |attribute| match do |object| !!DirectAssignmentMatchers::public_assign(object, attribute) end diffable end private def self.public_assign(object, attribute) begin object.public_send(:"#{attribute.to_s}=", 'test') true rescue NoMethodError false end end end RSpec.configure do |config| config.include DirectAssignmentMatchers end