Skip to content

Commit

Permalink
upgrade to expect syntax to fix more rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
whoward committed Feb 5, 2016
1 parent 3b071de commit 0d1b91d
Show file tree
Hide file tree
Showing 31 changed files with 526 additions and 526 deletions.
12 changes: 6 additions & 6 deletions spec/block_hierarchy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

context '#initialize' do
it 'begins with a empty block hierarchy' do
subject.new['foo'].should == []
expect(subject.new['foo']).to eq([])
end

it 'allows passing an optional hash to become the initial data' do
subject.new(foo: foo_block_a)['foo'].should == [foo_block_a]
expect(subject.new(foo: foo_block_a)['foo']).to eq([foo_block_a])
end
end

context '#[]' do
it 'returns an empty array for an undefined block' do
hierarchy['foo'].should == []
expect(hierarchy['foo']).to eq([])
end

it 'returns the whole chain from lowest to highest ancestor' do
Expand All @@ -33,17 +33,17 @@

context '#push' do
it 'assigns the block to the end of the hierarchy chain' do
hierarchy['foo'].should == []
expect(hierarchy['foo']).to eq([])
hierarchy << foo_block_a
hierarchy['foo'].should == [foo_block_a]
expect(hierarchy['foo']).to eq([foo_block_a])
end
end

context '#merge' do
it 'pushes each block in the passed hash onto the end of the chain' do
hierarchy << foo_block_a
hierarchy.merge(foo: foo_block_b)
hierarchy['foo'].should == [foo_block_a, foo_block_b]
expect(hierarchy['foo']).to eq([foo_block_a, foo_block_b])
end
end
end
12 changes: 6 additions & 6 deletions spec/cadenza_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
template = Fixture.read('templates/index.html.cadenza')
expected = Fixture.read('templates/index.html')

Cadenza.render(template, {}, context: context).should equal_html expected
expect(Cadenza.render(template, {}, context: context)).to equal_html expected
end

it 'should allow passing a scope' do
template = Fixture.read('templates/test.html.cadenza')

Cadenza.render(template, { pi: 3.14159 }, context: context).should == 'abc3.14159ghi'
Cadenza.render(template, { pi: 'def' }, context: context).should == 'abcdefghi'
expect(Cadenza.render(template, { pi: 3.14159 }, context: context)).to eq('abc3.14159ghi')
expect(Cadenza.render(template, { pi: 'def' }, context: context)).to eq('abcdefghi')
end

it "should define a render function to load a template off the context's load system and render a string" do
expected = Fixture.read('templates/index.html')

Cadenza.render_template('index.html.cadenza', {}, context: context).should equal_html expected
expect(Cadenza.render_template('index.html.cadenza', {}, context: context)).to equal_html expected
end

it 'should allow passing a scope' do
Cadenza.render_template('test.html.cadenza', { pi: 3.14159 }, context: context).should == 'abc3.14159ghi'
Cadenza.render_template('test.html.cadenza', { pi: 'foo' }, context: context).should == 'abcfooghi'
expect(Cadenza.render_template('test.html.cadenza', { pi: 3.14159 }, context: context)).to eq('abc3.14159ghi')
expect(Cadenza.render_template('test.html.cadenza', { pi: 'foo' }, context: context)).to eq('abcfooghi')
end
end
14 changes: 7 additions & 7 deletions spec/context_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@
subject { TestContextObject.new }

it 'invokes public methods' do
subject.send(:invoke_context_method, 'public_visibility_method').should == 123
expect(subject.send(:invoke_context_method, 'public_visibility_method')).to eq(123)
end

it "doesn't invoke private methods" do
subject.send(:invoke_context_method, 'private_visibility_method').should.nil?
expect(subject.send(:invoke_context_method, 'private_visibility_method')).to eq nil
end

it "doesn't invoke protected methods" do
subject.send(:invoke_context_method, 'protected_visibility_method').should.nil?
expect(subject.send(:invoke_context_method, 'protected_visibility_method')).to eq nil
end

it 'invokes before_method if defined' do
subject.should_receive(:before_method).once
expect(subject).to receive(:before_method).once
subject.send(:invoke_context_method, 'public_visibility_method')
end

it 'invokes after_method if defined' do
subject.should_receive(:after_method).once
expect(subject).to receive(:after_method).once
subject.send(:invoke_context_method, 'public_visibility_method')
end

it "invokes missing_context_method if trying to invoke a method which doesn't exist" do
subject.should_receive(:missing_context_method).with('foo').once
expect(subject).to receive(:missing_context_method).with('foo').once
subject.send(:invoke_context_method, 'foo')
end

context '#context_methods' do
it 'returns only the public methods defined on it, not public methods of Object' do
subject.send(:context_methods).should == %w(public_visibility_method)
expect(subject.send(:context_methods)).to eq(%w(public_visibility_method))
end
end
end
88 changes: 44 additions & 44 deletions spec/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

describe Cadenza::Context do
it 'should start with an empty stack' do
Cadenza::Context.new.stack.should == [{}]
expect(Cadenza::Context.new.stack).to eq([{}])
end

it 'should begin with whiny template loading disabled' do
Cadenza::Context.new.whiny_template_loading.should == false
expect(Cadenza::Context.new.whiny_template_loading).to eq(false)
end

it "should take a hash and define that as the stack's first element" do
Cadenza::Context.new(foo: 'bar').stack.should == [{ foo: 'bar' }]
expect(Cadenza::Context.new(foo: 'bar').stack).to eq([{ foo: 'bar' }])
end

it 'should allow pushing new values onto the stack' do
context = Cadenza::Context.new(foo: 'bar')
context.push(baz: 'foo')

context.stack.should == [{ foo: 'bar' }, { baz: 'foo' }]
expect(context.stack).to eq([{ foo: 'bar' }, { baz: 'foo' }])
end

context '#clone' do
Expand All @@ -37,21 +37,21 @@
end

it "should duplicate it's stack" do
context.clone.stack.should_not equal context.stack
context.clone.stack.should == context.stack
expect(context.clone.stack).not_to equal context.stack
expect(context.clone.stack).to eq(context.stack)
end

it "should not duplicate the values of it's stack" do
context.clone.stack.first[:foo].should equal context.stack.first[:foo]
expect(context.clone.stack.first[:foo]).to equal context.stack.first[:foo]
end

it "should duplicate it's loader list" do
context.clone.loaders.should_not equal context.loaders
context.clone.loaders.should == context.loaders
expect(context.clone.loaders).not_to equal context.loaders
expect(context.clone.loaders).to eq(context.loaders)
end

it 'should not duplicate the loaders inside the list' do
context.clone.loaders.first.should equal context.loaders.first
expect(context.clone.loaders.first).to equal context.loaders.first
end
end

Expand All @@ -67,64 +67,64 @@
let(:context) { context_class.new(scope) }

it 'should retrieve the value of an identifier' do
context.lookup('foo').should == { bar: 'baz' }
expect(context.lookup('foo')).to eq(bar: 'baz')
end

it 'should retrieve the value of an identifier with dot notation' do
context.lookup('foo.bar').should == 'baz'
expect(context.lookup('foo.bar')).to eq('baz')
end

it 'should retrieve the value of an identifier in a higher scope' do
context.push(baz: 'foo')
context.lookup('baz').should == 'foo'
expect(context.lookup('baz')).to eq('foo')
end

it 'should retreive the overriden value of an identifier in a higher scope' do
context.push(foo: 'baz')
context.lookup('foo').should == 'baz'
expect(context.lookup('foo')).to eq('baz')
end

it 'should allow popping the top scope off the stack' do
context.push(foo: 'baz')

context.lookup('foo').should == 'baz'
expect(context.lookup('foo')).to eq('baz')

context.pop

context.lookup('foo').should == { bar: 'baz' }
expect(context.lookup('foo')).to eq(bar: 'baz')
end

it 'should look up array indexes' do
context.lookup('alphabet.1').should == 'b'
expect(context.lookup('alphabet.1')).to eq('b')
end

it "should look up a function by it's name" do
context.lookup('assign').should == assign
expect(context.lookup('assign')).to eq(assign)
end

it 'should look up a function instead of a variable of the same name' do
context.push(assign: 'foo')
context.lookup('assign').should == assign
expect(context.lookup('assign')).to eq(assign)
end

it 'calls methods on ContextObjects' do
context.lookup('obj.public_visibility_method').should == 123
expect(context.lookup('obj.public_visibility_method')).to eq(123)
end

it "doesn't look up values on objects which are not ContextObjects" do
context.lookup('abc.def').should.nil?
expect(context.lookup('abc.def')).to eq nil
end
end

context '#assign' do
let(:context) { Cadenza::Context.new }

it 'should assign a value to the current stack' do
context.lookup('foo').should be_nil
expect(context.lookup('foo')).to be_nil

-> { context.assign(:foo, 'bar') }.should_not change(context.stack, :length)
expect { context.assign(:foo, 'bar') }.not_to change(context.stack, :length)

context.lookup('foo').should == 'bar'
expect(context.lookup('foo')).to eq('bar')
end
end

Expand All @@ -135,51 +135,51 @@
let(:template) { FixtureSyntaxTree.new('text/basic.yml').document }

it 'should start with an empty list of loaders' do
context.loaders.should == []
expect(context.loaders).to eq([])
end

it 'should allow adding a loader class' do
context.add_loader filesystem_loader
context.loaders.should == [filesystem_loader]
expect(context.loaders).to eq([filesystem_loader])
end

it 'should allow adding a load path' do
path = Fixture.filename('foo')
context.add_load_path(path)

context.loaders.should have(1).item
context.loaders[0].should be_a Cadenza::FilesystemLoader
context.loaders[0].path.should == path
expect(context.loaders.size).to eq(1)
expect(context.loaders[0]).to be_a Cadenza::FilesystemLoader
expect(context.loaders[0].path).to eq(path)
end

it 'should return nil if no template was found' do
context.add_loader(filesystem_loader)
context.add_loader(Cadenza::FilesystemLoader.new(template_path))

context.load_source('fake.html').should be_nil
context.load_template('fake.html').should be_nil
expect(context.load_source('fake.html')).to be_nil
expect(context.load_template('fake.html')).to be_nil
end

it 'should raise an error if no template was found and whiny template loading is enabled' do
context.whiny_template_loading = true

lambda do
expect do
context.load_source('fake.html')
end.should raise_error Cadenza::TemplateNotFoundError
end.to raise_error Cadenza::TemplateNotFoundError

lambda do
expect do
context.load_template('fake.html')
end.should raise_error Cadenza::TemplateNotFoundError
end.to raise_error Cadenza::TemplateNotFoundError
end

it 'should always raise the exception regardless of whiny template loading when the bang is provided' do
lambda do
expect do
context.load_source!('fake.html')
end.should raise_error Cadenza::TemplateNotFoundError
end.to raise_error Cadenza::TemplateNotFoundError

lambda do
expect do
context.load_template!('fake.html')
end.should raise_error Cadenza::TemplateNotFoundError
end.to raise_error Cadenza::TemplateNotFoundError
end

it 'should traverse the loaders in order to find the first loaded template' do
Expand All @@ -188,17 +188,17 @@
context.add_loader(filesystem_loader)
context.add_loader(other_loader)

filesystem_loader.should_receive(:load_template).with('template.html').and_return(template)
other_loader.stub(:load_template).and_return('foo')
expect(filesystem_loader).to receive(:load_template).with('template.html').and_return(template)
allow(other_loader).to receive(:load_template).and_return('foo')

context.load_template('template.html').should == template
expect(context.load_template('template.html')).to eq(template)
end

it 'should provide a method to clear the loaders' do
context.add_loader(filesystem_loader)
context.loaders.should_not be_empty
expect(context.loaders).not_to be_empty
context.clear_loaders
context.loaders.should be_empty
expect(context.loaders).to be_empty
end
end
end
16 changes: 8 additions & 8 deletions spec/filesystem_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
it 'should return the parsed template tree if the file exists' do
template = loader.load_template('test.html.cadenza')

template.should_not be_nil
template.should equal_syntax_tree 'templates/test.parse.yml'
expect(template).not_to be_nil
expect(template).to equal_syntax_tree 'templates/test.parse.yml'
end
end

context '#load_source' do
it 'should return the source if the file is a file symlink' do
loader.load_source('test.html.cadenza').should == Fixture.read('templates/test.html.cadenza')
expect(loader.load_source('test.html.cadenza')).to eq(Fixture.read('templates/test.html.cadenza'))
end

it 'should return nil if the file does not exist' do
loader.load_source('fake.html.cadenza').should be_nil
expect(loader.load_source('fake.html.cadenza')).to be_nil
end

it 'should return nil if the file is a directory' do
loader.load_source('test-directory').should be_nil
expect(loader.load_source('test-directory')).to be_nil
end

it 'should return nil if the file is a directory symlink' do
loader.load_source('test-directory-symlink').should be_nil
expect(loader.load_source('test-directory-symlink')).to be_nil
end

it 'should return the source if the file is a file symlink' do
loader.load_source('test-file-symlink').should == Fixture.read('templates/test.html.cadenza')
expect(loader.load_source('test-file-symlink')).to eq(Fixture.read('templates/test.html.cadenza'))
end

it 'should return the parsed template tree if the file is in a subdirectory' do
loader.load_source('test-directory/test.html.cadenza').should == Fixture.read('templates/test-directory/test.html.cadenza')
expect(loader.load_source('test-directory/test.html.cadenza')).to eq(Fixture.read('templates/test-directory/test.html.cadenza'))
end
end
end

0 comments on commit 0d1b91d

Please sign in to comment.