[rspec-users] catching errors, rspec basics

Andrew WC Brown omen.king at gmail.com
Tue Jan 29 19:55:02 EST 2008


try it, does the same thing ='(

On Jan 29, 2008 7:49 PM, Shane Mingins <smingins at elctech.com> wrote:

> Are you looking for something like this
> lambda { @audience.stats = 'Market Goblin' }.should raise_error
>
>
> On 30/01/2008, at 1:48 PM, Andrew WC Brown wrote:
>
> Trying to spec the following but don't know if I'm using the right
> matcher.
> How do I spec? Plz, sugar on tops.
>
> Audience.stats
> - should have a stats of 80 when passed a flux of 10
> - should return an error when passed a string (ERROR - 1)
>
> 1)
> TypeError in 'Audience.stats should return an error when passed a string'
> String can't be coerced into Fixnum
> ./audience.rb:11:in `*'
> ./audience.rb:11:in `stats='
> ./audience_spec.rb:29:
>
> Finished in 0.006333 seconds
>
> 2 examples, 1 failure
> monsterbox:spec andrew_wc_brown$
>
>
>
> class Audience
>
>   attr_accessor :stats
>
>   def initialize(name = nil,value = nil)
>     @name ||= 'all'
>     @value ||= value
>   end
>
>   def stats=(flux)
>     @stats = @value * flux / 0.025
>   end
>
>   def market_share
>     "The Market share is for #{@name} at a high of #{@stats}"
>   end
>
> end
>
> describe "Audience.stats" do
>
> before :all do
>   @audience = Audience.new(nil,20)
> end
>
>   it  "should have a stats of 80 when passed a flux of 10" do
>     @audience.stats = 10
>     @audience.stats.should == 8000
>   end
>
>   it "should return an error when passed a string" do
>     @audience.stats = 'Market Goblin'
>     @audience.stats.should raise_error
>   end
> end
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
>
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20080129/313a1992/attachment.html 


More information about the rspec-users mailing list