Sha256: 39519caa2ccdbee6320e4249d9a3457d91277c9601c03c31f3c837628102e58d

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require_relative '../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

5 entries across 5 versions & 1 rubygems

Version Path
dependor-0.0.5 spec/dependor/injectable_spec.rb
dependor-0.0.4 spec/dependor/injectable_spec.rb
dependor-0.0.3 spec/dependor/injectable_spec.rb
dependor-0.0.2 spec/dependor/injectable_spec.rb
dependor-0.0.1 spec/dependor/injectable_spec.rb