Sha256: 9e0a7a225a1405507d8e883a7dfa583c015284d5072cfa85aee2bb3729c731fb

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

describe Dependor::Injectable do
  class SampleInjector
    def foo
      "foo"
    end
  end

  class SampleInjectable
    extend Dependor::Injectable
    inject_from(SampleInjector)

    inject :foo

    def hello_foo
      "hello #{foo}"
    end
  end

  class SampleInjectableWithoutAnInjector
    extend Dependor::Injectable

    inject :foo

    def hello_foo
      "hello #{foo}"
    end
  end

  it "requires the class to provide injector method" do
    injectable = SampleInjectableWithoutAnInjector.new

    expect do
      injectable.hello_foo
    end.to raise_exception
  end

  it "uses the provided injector" do
    injectable = SampleInjectable.new

    injectable.hello_foo.should == 'hello foo'
  end

  describe "typical Rails usage" do
    class ApplicationController
      extend Dependor::Injectable
      inject_from SampleInjector
    end

    class PostsController < ApplicationController
      inject :foo

      def get
        "render #{foo}"
      end
    end

    it "should return foo value in child controller" do
      PostsController.new.get.should == "render foo"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dependor-1.0.1 spec/dependor/injectable_spec.rb
dependor-1.0.0 spec/dependor/injectable_spec.rb
dependor-0.0.6 spec/dependor/injectable_spec.rb