Testing an Independent Mixin With RSpec

Objective: write a spec for the Inventory::Query mixin.

Note: the mixin is independent of the including class as it does not depend on any instance variables or instance methods.

Original Approach

class InventoryQueryTest
  include Inventory::Query
end
subject(:inventory_query) { InventoryQueryTest.new }

Preferred Approach

subject(:inventory_query) { (Class.new { include Inventory::Query }).new }

Advantage

Simpler and avoids polluting the global namespace with a test class.

Written on August 22, 2016 by alistairmckinnell