1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
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
|