File: setting_path_spec.rb

package info (click to toggle)
ruby-configurate 0.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 144 kB
  • ctags: 55
  • sloc: ruby: 666; makefile: 5
file content (109 lines) | stat: -rw-r--r-- 2,871 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'spec_helper'

describe Configurate::SettingPath do
  let(:normal_path) { described_class.new([:foo]) }
  let(:question_path) { described_class.new([:foo?]) }
  let(:setter_path) { described_class.new([:foo=]) }
  let(:long_path) { described_class.new(["foo", "bar?"]) }

  describe "#initialize" do
    context "with a string" do
      it "creates a path" do
        described_class.new(long_path.to_s).should == long_path
      end
    end
  end

  describe "#is_question?" do
    context "with a question signature as setting" do
      subject { question_path.is_question? }
      it { should be_true }
    end

    context "with a normal path as setting" do
      subject { normal_path.is_question? }
      it { should be_false }
    end
  end

  describe "#is_setter?" do
    context "with a setter signature as setting" do
      subject { setter_path.is_setter? } 
      it { should be_true }
    end

    context "with a normal path as setting" do
      subject { normal_path.is_setter? }
      it { should be_false }
    end
  end

  describe "#initialize_copy" do
    it "modifying a copy leaves the original unchanged" do
      original = described_class.new ["foo", "bar"]
      copy = original.clone
      copy << "baz"
      copy.should include "baz"
      original.should_not include "baz"
    end
  end


  describe "#is_question_or_setter?" do
    context "with a question signature as setting" do
      subject { question_path.is_question_or_setter? }
      it { should be_true }
    end

    context "with a setter signature as setting" do
      subject { setter_path.is_question_or_setter? } 
      it { should be_true }
    end

    context "with a normal path as setting" do
      subject { normal_path.is_question_or_setter? }
      it { should be_false }
    end
  end

  describe "#each" do
    it "should strip special characters" do
      long_path.all? { |c| c.include? "?" }.should be_false
    end
  end

  [:join, :first, :last, :shift, :pop].each do |method|
    describe "##{method}" do
      subject { question_path.public_send method }
      it { should_not include "?" }
    end
  end

  [:<<, :unshift, :push].each do |method|
    describe "##{method}" do
      it 'converts the argument to a string' do
        arg = mock
        arg.should_receive(:to_s).and_return('bar')
        described_class.new.public_send method, arg
      end
    end
  end

  describe "#to_s" do
    let(:path) { "example.path" }
    subject { described_class.new(path.split(".")).to_s }
    it { should == path }

    context "with a question signature as setting" do
      subject { described_class.new("#{path}?".split(".")).to_s }
      it { should == path }
    end
  end

  describe "#inspect" do
    it "includes the dotted path" do
      path = described_class.new([:foo, :bar])
      path.inspect.should include "foo.bar"
    end
  end
end