Sha256: 9fdabb2c8bda36084207e41862c83614513934f90f741edd11473b52786e67dd

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'rspec'
require 'required_options'

describe RequiredOptions do
  class Dummy
    def self.major_method(opts = {})
      required_options opts, :speed
    end

    def minor_method(options = {})
      required_options options, :dyno, "rpm"
    end
  end

  context "when required options are passed" do
    context "and a class method" do
      it "will not raise an exception" do
        lambda do
          Dummy.major_method(:speed => "")
        end.should_not raise_error(MissingOptions)
      end
    end

    context "and an instance method" do
      it "will not raise an exception" do
        lambda do
          Dummy.new.minor_method(
            :dyno => "",
            "rpm" => ""
          )
        end.should_not raise_error(MissingOptions)
      end
    end
  end

  context "when required options are missing" do
    context "and a class method" do
      it "will raise a MissingOptions exception" do
        lambda do
          Dummy.major_method
        end.should raise_error(MissingOptions, ":speed")
      end
    end

    context "and an instance method" do
      it "will raise a MissingOptions exception" do
        lambda do
          Dummy.new.minor_method
        end.should raise_error(MissingOptions, ":dyno, rpm")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
required_options-0.6.1 spec/required_options_spec.rb
required_options-0.6.0 spec/required_options_spec.rb
required_options-0.5.0 spec/required_options_spec.rb