File: isolate_spec.rb

package info (click to toggle)
ruby-dependor 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264 kB
  • sloc: ruby: 557; makefile: 2; sh: 1
file content (49 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (4)
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
require 'spec_helper'

describe Dependor::Isolate do
  class ExampleSubject
    takes :foo, :bar
  end

  class ExampleContext
    include Dependor::Isolate

    def subject
      isolate{ExampleSubject}
    end

    def override
      bar = "bar was overriden"
      isolate{ExampleSubject}
    end

    def parameters
      isolate(ExampleSubject, bar: "the parameter")
    end

    def foo
      "the foo stub"
    end

    def bar
      "the bar stub"
    end
  end

  let(:context) { ExampleContext.new }

  it "injects the subject's dependencies using methods on context" do
    context.subject.foo.should == "the foo stub"
    context.subject.bar.should == "the bar stub"
  end

  it "allows overriding dependencies with variables" do
    context.override.bar.should == "bar was overriden"
    context.override.foo.should == "the foo stub"
  end

  it "allows overriding dependencies with parameters" do
    context.parameters.bar.should == "the parameter"
    context.parameters.foo.should == "the foo stub"
  end
end