spec/sitehub/collection/route_collection_spec.rb in sitehub-0.4.2 vs spec/sitehub/collection/route_collection_spec.rb in sitehub-0.4.3

- old
+ new

@@ -1,14 +1,12 @@ require 'sitehub/collection/route_collection' require 'sitehub/forward_proxy' class SiteHub - describe Collection::RouteCollection do + let(:route_without_rule) { ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name) } - let(:route_without_rule) { ForwardProxy.new(url: :url, id: :id,sitehub_cookie_name: :cookie_name) } - it 'is a collection' do expect(subject).to be_a(Collection) end describe '#add' do @@ -32,11 +30,11 @@ end describe '#valid?' do context 'route added' do it 'returns true' do - subject.add :id,route_without_rule + subject.add :id, route_without_rule expect(subject).to be_valid end end context 'no routes added' do @@ -45,47 +43,51 @@ end end end describe '#resolve' do - context 'no rule on route' do it 'returns the route' do - route_without_rule = ForwardProxy.new(url: :url, id: :id,sitehub_cookie_name: :cookie_name) + route_without_rule = ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name) subject.add(:id, route_without_rule) expect(subject.resolve({})).to be(route_without_rule) end end context 'rule on route' do - it 'passes the environment to the rule' do request_env = {} - rule = proc {|env| env[:env_passed_in] = true} + rule = proc { |env| env[:env_passed_in] = true } - proxy = ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name) + proxy = ForwardProxy.new(url: :url, + id: :id, + sitehub_cookie_name: :cookie_name) proxy.rule(rule) subject.add(:id, proxy) subject.resolve(env: request_env) expect(request_env[:env_passed_in]).to eq(true) end context 'rule applies' do it 'returns the route' do - route_with_rule = ForwardProxy.new(url: :url, id: :id, rule: proc { true }, sitehub_cookie_name: :cookie_name) + route_with_rule = ForwardProxy.new(url: :url, + id: :id, + rule: proc { true }, + sitehub_cookie_name: :cookie_name) subject.add(:id, route_with_rule) expect(subject.resolve({})).to be(route_with_rule) end - end context 'rule does not apply' do it 'returns nil' do - route_with_rule = ForwardProxy.new(url: :url, id: :id, sitehub_cookie_name: :cookie_name, rule: proc { false }) + route_with_rule = ForwardProxy.new(url: :url, + id: :id, + sitehub_cookie_name: :cookie_name, + rule: proc { false }) subject.add(:id, route_with_rule) expect(subject.resolve({})).to eq(nil) end end end end end - -end \ No newline at end of file +end