Skip to content

Commit c479486

Browse files
committed
Change to move configuration specs.
1 parent 7381b43 commit c479486

3 files changed

Lines changed: 102 additions & 100 deletions

File tree

spec/github/api/property_spec.rb

Lines changed: 0 additions & 100 deletions
This file was deleted.

spec/unit/api/config_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
RSpec.describe Github::API::Config, 'inheritance' do
6+
let(:top) { Class.new(Github::API::Config) }
7+
let(:middle) { Class.new(top) }
8+
let(:bottom) { Class.new(middle) }
9+
10+
it "has no properties" do
11+
expect(top.property_names).to be_empty
12+
expect(middle.property_names).to be_empty
13+
expect(bottom.property_names).to be_empty
14+
end
15+
16+
it "inherits properties down" do
17+
top.property :magic
18+
expect(top.property_names.include?(:magic)).to be_true
19+
expect(middle.property_names.include?(:magic)).to be_true
20+
expect(bottom.property_names.include?(:magic)).to be_true
21+
end
22+
23+
it "doesn't inherit properties up" do
24+
middle.property :mushroom
25+
expect(top.property_names.include?(:mushroom)).to be_false
26+
expect(middle.property_names.include?(:mushroom)).to be_true
27+
expect(bottom.property_names.include?(:mushroom)).to be_true
28+
end
29+
30+
it "allows to override a default option" do
31+
top.property :override
32+
middle.property :override, default: 66
33+
expect(bottom.property_names.include?(:override))
34+
expect(bottom.new.override).to eql(66)
35+
end
36+
37+
it "allows to clear existing default" do
38+
top.property :simple, default: 0
39+
middle.property :simple, default: 1
40+
expect(top.new.simple).to eql(0)
41+
expect(middle.new.simple).to eql(1)
42+
expect(bottom.new.simple).to eql(1)
43+
end
44+
end

spec/unit/api/property_spec.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
class ConfigTest < Github::API::Config
6+
property :test
7+
property :foo, default: :bar
8+
property :bar
9+
end
10+
11+
class SubclassTest < ConfigTest
12+
property :test, default: 'Piotr'
13+
property :extra, default: 0
14+
end
15+
16+
RSpec.describe ConfigTest, '#property' do
17+
18+
subject(:example) { described_class.new }
19+
20+
it "doesn't have property" do
21+
expect(Github::API::Config.property?('test')).to eq(false)
22+
end
23+
24+
it { expect(example).to respond_to(:test) }
25+
it { expect(example).to respond_to(:test=) }
26+
27+
it 'defaults property to nil' do
28+
expect(example.test).to eql nil
29+
end
30+
31+
it 'defaults to :bar' do
32+
expect(example.foo).to eql :bar
33+
end
34+
35+
it 'allows to write and read property' do
36+
subject.bar = :a
37+
expect(example.bar).to eql :a
38+
end
39+
40+
it 'allows to fetch all properties' do
41+
expect(example.fetch.keys).to match_array([:bar, :foo, :test])
42+
end
43+
44+
it 'allows to fetch individual property' do
45+
expect(example.fetch(:foo)).to eq(:bar)
46+
end
47+
end
48+
49+
RSpec.describe SubclassTest, '#property' do
50+
subject(:subclass) { described_class.new }
51+
52+
it { expect(subclass.extra).to be_zero }
53+
54+
it { expect(subclass).to respond_to(:test) }
55+
it { expect(subclass).to respond_to(:test=) }
56+
it { expect(subclass).to respond_to(:extra) }
57+
it { expect(subclass).to respond_to(:extra=) }
58+
end

0 commit comments

Comments
 (0)