[rspec-users] ANN: RSpec 0.9.0 beta-1 available for download.

Roberto Soares roberto at techmobil.com.br
Thu Apr 5 12:56:37 EDT 2007


from: rspec/examples/stack_spec.rb

require File.dirname(__FILE__) + '/spec_helper'
require File.dirname(__FILE__) + "/stack"

describe Stack do
  setup do
    @stack = Stack.new
    ["a","b","c"].each { |x| @stack.push x }
  end

  it "should add to the top when sent #push" do
    @stack.push "d"
    @stack.peek.should == "d"
  end

  it "should return the top item when sent #peek" do
    @stack.peek.should == "c"
  end

  it "should NOT remove the top item when sent #peek" do
    @stack.peek.should == "c"
    @stack.peek.should == "c"
  end

  it "should return the top item when sent #pop" do
    @stack.pop.should == "c"
  end

  it "should remove the top item when sent #pop" do
    @stack.pop.should == "c"
    @stack.pop.should == "b"
  end
end

describe Stack, " (empty)" do
  setup do
    @stack = Stack.new
  end

  # NOTE that this one auto-generates the description "should be empty"
  specify { @stack.should be_empty }

  it "should no longer be empty after #push" do
    @stack.push "anything"
    @stack.should_not be_empty
  end

  it "should complain when sent #peek" do
    lambda { @stack.peek }.should raise_error(StackUnderflowError)
  end

  it "should complain when sent #pop" do
    lambda { @stack.pop }.should raise_error(StackUnderflowError)
  end
end

describe Stack, " (with one item)" do
  setup do
    @stack = Stack.new
    @stack.push 3
  end

  # NOTE that this one auto-generates the description "should not be empty"
  specify { @stack.should_not be_empty }

  it "should remain not empty after #peek" do
    @stack.peek
    @stack.should_not be_empty
  end

  it "should become empty after #pop" do
    @stack.pop
    @stack.should be_empty
  end
end

describe Stack, " (with one item less than capacity)" do
  setup do
    @stack = Stack.new
    (1..9).each { |i| @stack.push i }
  end

  # NOTE that this one auto-generates the description "should not be full"
  specify { @stack.should_not be_full }

  it "should become full after #push" do
    @stack.push Object.new
    @stack.should be_full
  end
end

describe Stack, " (full)" do
  setup do
    @stack = Stack.new
    (1..10).each { |i| @stack.push i }
  end

  # NOTE that this one auto-generates the description "should be full"
  it { @stack.should be_full }

  it "should remain full after #peek" do
    @stack.peek
    @stack.should be_full
  end

  it "should no longer be full after #pop" do
    @stack.pop
    @stack.should_not be_full
  end

  it "should complain on #push" do
    lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
  end
end

On 4/5/07, Wincent Colaiuta <win at wincent.com> wrote:
>
> El 4/4/2007, a las 18:33, aslak hellesoy escribió:
>
> > RSpec 0.9 introduces a new API for expectations, which essentially
> > means that your underscores go away
>
> Can you please give an example of what this looks like? I've looked
> at the various "dot vs underscore" discussions on the lists so I'm
> interested to see what the new style is.
>
> Cheers,
> Wincent
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>



-- 
Roberto Soares
Diretor de P&D da Techmobil
http://roberto.techmobil.com.br
73 8105-4337
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070405/e7eb20c5/attachment-0001.html 


More information about the rspec-users mailing list