Skip to content

Instantly share code, notes, and snippets.

@danielpclark
Created February 21, 2016 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpclark/4f0c9b42658fbe1cbde8 to your computer and use it in GitHub Desktop.
Save danielpclark/4f0c9b42658fbe1cbde8 to your computer and use it in GitHub Desktop.

This is my ideal design in Minitest

require 'test_helper'
describe "Thing" do
  let(:cow) { Array.new }

  it "does the thing" do
    _(cow.length).must_be :<, 3

    value do
      cow << :woof
    end.must_change "cow.count"
  end
end

But this blows up in my face saying assert_difference not defined and the following remedies it.

require 'test_helper'
class ThingTest < ActiveSupport::TestCase
  describe "Thing" do
    let(:cow) { Array.new }

    it "does the thing" do
      _(cow.length).must_be :<, 3

      value do
        cow << :woof
      end.must_change "cow.count"
    end
  end
end

This brings in all the right methods into scope for my tests to work. But I find it ugly and weird to just use a describe block inside a class block. Very un-class-like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment