Skip to content

davidmccabe/after_sending

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

A convenience method. In our Rails model tests, we often had:

    class ThingTest < ActiveSupport::TestCase
      def new_thing(attributes = {})
        ...
    
        thing = Thing.new(attributes)
        thing.valid?  # Allows us to use errors method on newly-created things.
        thing
      end
  
      def some_test
        assert_equal ["an error message"], new_thing(:bogus => "attributes").errors[:base]
      end
  
      ...
    end

Well, this part is ugly:

    thing = Thing.new(attributes)
    thing.valid?  # Allows us to use errors method on newly-created things.
    thing

We would like instead to say:

    Thing.new(attributes).after_sending {valid?}

This is similar to the standard method Object#tap, but has a better name and better syntax.

We also support this syntax, but are not sure we like it:

    Thing.new(attributes).after_sending.valid?

About

An Ruby method Object#after_sending

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages