Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'rspec' of https://github.com/stjhimy/sinatra-contrib in…
…to stjhimy-rspec
  • Loading branch information
Zachary Scott committed Jul 20, 2016
2 parents c500bb1 + 8003802 commit c4c08c2
Show file tree
Hide file tree
Showing 13 changed files with 551 additions and 541 deletions.
2 changes: 1 addition & 1 deletion sinatra-contrib/sinatra-contrib.gemspec
Expand Up @@ -223,7 +223,7 @@ Gem::Specification.new do |s|
s.add_dependency "rack-protection"
s.add_dependency "multi_json"

s.add_development_dependency "rspec", "~> 2.3"
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "haml"
s.add_development_dependency "erubis"
s.add_development_dependency "slim"
Expand Down
6 changes: 3 additions & 3 deletions sinatra-contrib/spec/capture_spec.rb
Expand Up @@ -23,11 +23,11 @@ def render(engine, template)
require "#{engine}"

it "captures content" do
render(engine, "simple_#{lang}").should == "Say Hello World!"
expect(render(engine, "simple_#{lang}")).to eq("Say Hello World!")
end

it "allows nested captures" do
render(engine, "nested_#{lang}").should == "Say Hello World!"
expect(render(engine, "nested_#{lang}")).to eq("Say Hello World!")
end
end

Expand All @@ -39,7 +39,7 @@ def render(engine, template)
it_behaves_like "a template language", :erb

it "handles utf-8 encoding" do
render(:erb, "utf_8").should == "UTF-8 –"
expect(render(:erb, "utf_8")).to eq("UTF-8 –")
end

it "handles ISO-8859-1 encoding" do
Expand Down
32 changes: 16 additions & 16 deletions sinatra-contrib/spec/config_file_spec.rb
Expand Up @@ -12,51 +12,51 @@ def config_file(*args, &block)

it 'should set options from a simple config_file' do
config_file 'key_value.yml'
settings.foo.should == 'bar'
settings.something.should == 42
expect(settings.foo).to eq('bar')
expect(settings.something).to eq(42)
end

it 'should create indifferent hashes' do
config_file 'key_value.yml'
settings.nested['a'].should == 1
settings.nested[:a].should == 1
expect(settings.nested['a']).to eq(1)
expect(settings.nested[:a]).to eq(1)
end

it 'should render options in ERB tags' do
config_file 'key_value.yml.erb'
settings.foo.should == "bar"
settings.something.should == 42
settings.nested['a'].should == 1
settings.nested[:a].should == 1
settings.nested['b'].should == 2
settings.nested[:b].should == 2
expect(settings.foo).to eq("bar")
expect(settings.something).to eq(42)
expect(settings.nested['a']).to eq(1)
expect(settings.nested[:a]).to eq(1)
expect(settings.nested['b']).to eq(2)
expect(settings.nested[:b]).to eq(2)
end

it 'should recognize env specific settings per file' do
config_file 'with_envs.yml'
settings.foo.should == 'test'
expect(settings.foo).to eq('test')
end

it 'should recognize env specific settings per setting' do
config_file 'with_nested_envs.yml'
settings.database[:adapter].should == 'sqlite'
expect(settings.database[:adapter]).to eq('sqlite')
end

it 'should not set present values to nil if the current env is missing' do
# first let's check the test is actually working properly
config_file('missing_env.yml') { set :foo => 42, :environment => :production }
settings.foo.should == 10
expect(settings.foo).to eq(10)
# now test it
config_file('missing_env.yml') { set :foo => 42, :environment => :test }
settings.foo.should == 42
expect(settings.foo).to eq(42)
end

it 'should prioritize settings in latter files' do
# first let's check the test is actually working properly
config_file 'key_value.yml'
settings.foo.should == 'bar'
expect(settings.foo).to eq('bar')
# now test it
config_file 'key_value_override.yml'
settings.foo.should == 'foo'
expect(settings.foo).to eq('foo')
end
end
84 changes: 42 additions & 42 deletions sinatra-contrib/spec/content_for_spec.rb
Expand Up @@ -19,56 +19,56 @@ def render(engine, template)
describe "without templates" do
it 'renders blocks declared with the same key you use when rendering' do
content_for(:foo) { "foo" }
yield_content(:foo).should == "foo"
expect(yield_content(:foo)).to eq("foo")
end

it 'renders blocks more than once' do
content_for(:foo) { "foo" }
3.times { yield_content(:foo).should == "foo" }
3.times { expect(yield_content(:foo)).to eq("foo") }
end

it 'does not render a block with a different key' do
content_for(:bar) { "bar" }
yield_content(:foo).should be_empty
expect(yield_content(:foo)).to be_empty
end

it 'renders default content if no block matches the key and a default block is specified' do
content_for(:bar) { "bar" }
yield_content(:foo) { "foo" }.should == "foo"
expect(yield_content(:foo) { "foo" }).to eq("foo")
end

it 'renders multiple blocks with the same key' do
content_for(:foo) { "foo" }
content_for(:foo) { "bar" }
content_for(:bar) { "WON'T RENDER ME" }
content_for(:foo) { "baz" }
yield_content(:foo).should == "foobarbaz"
expect(yield_content(:foo)).to eq("foobarbaz")
end

it 'renders multiple blocks more than once' do
content_for(:foo) { "foo" }
content_for(:foo) { "bar" }
content_for(:bar) { "WON'T RENDER ME" }
content_for(:foo) { "baz" }
3.times { yield_content(:foo).should == "foobarbaz" }
3.times { expect(yield_content(:foo)).to eq("foobarbaz") }
end

it 'passes values to the blocks' do
content_for(:foo) { |a| a.upcase }
yield_content(:foo, 'a').should == "A"
yield_content(:foo, 'b').should == "B"
expect(yield_content(:foo, 'a')).to eq("A")
expect(yield_content(:foo, 'b')).to eq("B")
end

it 'clears named blocks with the specified key' do
content_for(:foo) { "foo" }
yield_content(:foo).should == "foo"
expect(yield_content(:foo)).to eq("foo")
clear_content_for(:foo)
yield_content(:foo).should be_empty
expect(yield_content(:foo)).to be_empty
end

it 'takes an immediate value instead of a block' do
content_for(:foo, "foo")
yield_content(:foo).should == "foo"
expect(yield_content(:foo)).to eq("foo")
end
end

Expand All @@ -81,101 +81,101 @@ def render(engine, template)
begin
require inner
rescue LoadError => e
pending "Skipping: " << e.message
skip "Skipping: " << e.message
end
end

describe "with yield_content in Ruby" do
it 'renders blocks declared with the same key you use when rendering' do
render inner, :same_key
yield_content(:foo).strip.should == "foo"
expect(yield_content(:foo).strip).to eq("foo")
end

it 'renders blocks more than once' do
render inner, :same_key
3.times { yield_content(:foo).strip.should == "foo" }
3.times { expect(yield_content(:foo).strip).to eq("foo") }
end

it 'does not render a block with a different key' do
render inner, :different_key
yield_content(:foo).should be_empty
expect(yield_content(:foo)).to be_empty
end

it 'renders default content if no block matches the key and a default block is specified' do
render inner, :different_key
yield_content(:foo) { "foo" }.should == "foo"
expect(yield_content(:foo) { "foo" }).to eq("foo")
end

it 'renders multiple blocks with the same key' do
render inner, :multiple_blocks
yield_content(:foo).gsub(/\s/, '').should == "foobarbaz"
expect(yield_content(:foo).gsub(/\s/, '')).to eq("foobarbaz")
end

it 'renders multiple blocks more than once' do
render inner, :multiple_blocks
3.times { yield_content(:foo).gsub(/\s/, '').should == "foobarbaz" }
3.times { expect(yield_content(:foo).gsub(/\s/, '')).to eq("foobarbaz") }
end

it 'passes values to the blocks' do
render inner, :takes_values
yield_content(:foo, 1, 2).gsub(/\s/, '').should == "<i>1</i>2"
expect(yield_content(:foo, 1, 2).gsub(/\s/, '')).to eq("<i>1</i>2")
end
end

describe "with content_for in Ruby" do
it 'renders blocks declared with the same key you use when rendering' do
content_for(:foo) { "foo" }
render(inner, :layout).should == "foo"
expect(render(inner, :layout)).to eq("foo")
end

it 'renders blocks more than once' do
content_for(:foo) { "foo" }
render(inner, :multiple_yields).should == "foofoofoo"
expect(render(inner, :multiple_yields)).to eq("foofoofoo")
end

it 'does not render a block with a different key' do
content_for(:bar) { "foo" }
render(inner, :layout).should be_empty
expect(render(inner, :layout)).to be_empty
end

it 'renders multiple blocks with the same key' do
content_for(:foo) { "foo" }
content_for(:foo) { "bar" }
content_for(:bar) { "WON'T RENDER ME" }
content_for(:foo) { "baz" }
render(inner, :layout).should == "foobarbaz"
expect(render(inner, :layout)).to eq("foobarbaz")
end

it 'renders multiple blocks more than once' do
content_for(:foo) { "foo" }
content_for(:foo) { "bar" }
content_for(:bar) { "WON'T RENDER ME" }
content_for(:foo) { "baz" }
render(inner, :multiple_yields).should == "foobarbazfoobarbazfoobarbaz"
expect(render(inner, :multiple_yields)).to eq("foobarbazfoobarbazfoobarbaz")
end

it 'passes values to the blocks' do
content_for(:foo) { |a,b| "<i>#{a}</i>#{b}" }
render(inner, :passes_values).should == "<i>1</i>2"
expect(render(inner, :passes_values)).to eq("<i>1</i>2")
end

it 'clears named blocks with the specified key' do
content_for(:foo) { "foo" }
render(inner, :layout).should == "foo"
expect(render(inner, :layout)).to eq("foo")
clear_content_for(:foo)
render(inner, :layout).should be_empty
expect(render(inner, :layout)).to be_empty
end
end

describe "with content_for? in Ruby" do
it 'renders block if key is set' do
content_for(:foo) { "foot" }
render(inner, :footer).should == "foot"
expect(render(inner, :footer)).to eq("foot")
end

it 'does not render a block if different key' do
content_for(:different_key) { "foot" }
render(inner, :footer).should be_empty
expect(render(inner, :footer)).to be_empty
end
end

Expand All @@ -189,7 +189,7 @@ def body
begin
require outer
rescue LoadError => e
pending "Skipping: " << e.message
skip "Skipping: " << e.message
end
end

Expand All @@ -206,33 +206,33 @@ def body
end

it 'renders blocks declared with the same key you use when rendering' do
get('/same_key').should be_ok
body.should == "foo"
expect(get('/same_key')).to be_ok
expect(body).to eq("foo")
end

it 'renders blocks more than once' do
get('/multiple_yields/same_key').should be_ok
body.should == "foofoofoo"
expect(get('/multiple_yields/same_key')).to be_ok
expect(body).to eq("foofoofoo")
end

it 'does not render a block with a different key' do
get('/different_key').should be_ok
body.should be_empty
expect(get('/different_key')).to be_ok
expect(body).to be_empty
end

it 'renders multiple blocks with the same key' do
get('/multiple_blocks').should be_ok
body.should == "foobarbaz"
expect(get('/multiple_blocks')).to be_ok
expect(body).to eq("foobarbaz")
end

it 'renders multiple blocks more than once' do
get('/multiple_yields/multiple_blocks').should be_ok
body.should == "foobarbazfoobarbazfoobarbaz"
expect(get('/multiple_yields/multiple_blocks')).to be_ok
expect(body).to eq("foobarbazfoobarbazfoobarbaz")
end

it 'passes values to the blocks' do
get('/passes_values/takes_values').should be_ok
body.should == "<i>1</i>2"
expect(get('/passes_values/takes_values')).to be_ok
expect(body).to eq("<i>1</i>2")
end
end
end
Expand Down

0 comments on commit c4c08c2

Please sign in to comment.