[rspec-users] [UNSOLVED] Possible Problem with RSpec

James B. Byrne byrnejb at harte-lyne.ca
Sat Nov 24 21:22:59 EST 2007


On Sat, November 24, 2007 20:48, James B. Byrne wrote:

>
> The problem was that I left out a column from the product migration that I
> referred to in the spec.
>

Sorry, but I need to revisit this again.  If the specs pass then I get no
rake error. If one spec fails then after the test reports I get a rake
error  and back trace.  Why?

OS = MS XP pro SP2
Ruby = 1.8.6
Rails = 1.2.5
RSpec = TRUNK d.20071123

product_spec.rb

--->
require File.dirname(__FILE__) + '/../spec_helper'

module ProductSpecHelper

  def  valid_product_attributes
   {
	:code => 'PROD1234CODE',
	:description  => 'a short description',
	:image_url => 'http://imageserver.tld.com/images/image.jpg',
	:price => 1234.56,
	:title => 'a test product'
   }
  end
end

describe Product do

include	ProductSpecHelper

  before(:each) do
    @product = Product.new
  end

  it "should have a title" do
     @product.attributes = valid_product_attributes.except(:title)
     @product.should have(1).error_on(:title)
     @product.title = 'a test product'
     @product.should be_valid
  end

  it "should have a description" do
     @product.attributes = valid_product_attributes.except(:description)
     @product.should have(1).error_on(:description)
     @product.description = 'a short description'
     @product.should be_valid
  end

  it "should have a valid image uri"

end
<---

app/models/product.rb

--->
class Product < ActiveRecord::Base

  validates_presence_of  :title
  validates_presence_of  :description

end
<---

Specs pass:
--->
C:\var\RSpec\depot>rake spec:models
(in C:/var/RSpec/depot)
NOTICE:  CREATE TABLE will create implicit sequence "products_id_seq" for
serial column "products.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"products_pkey" for table "products"

Product
- should have a valid image uri (PENDING: Not Yet Implemented)
- should have a description
- should have a title

Pending:
Product should have a valid image uri (Not Yet Implemented)

Finished in 0.985 seconds

3 examples, 0 failures, 1 pending
<---

Spec fails: (I changed the .should be_valid to .should_not be_valid)

--->
C:\var\RSpec\depot>rake spec:models  --trace
(in C:/var/RSpec/depot)
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:test:prepare
** Invoke db:test:clone (first_time)
** Invoke db:schema:dump (first_time)
** Invoke environment
** Execute db:schema:dump
** Invoke db:test:purge (first_time)
** Invoke environment
** Execute db:test:purge
** Execute db:test:clone
** Invoke db:schema:load (first_time)
** Invoke environment
** Execute db:schema:load
NOTICE:  CREATE TABLE will create implicit sequence "products_id_seq" for
serial column "products.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"products_pkey" for table "products"
** Execute spec:models

Product
- should have a valid image uri (PENDING: Not Yet Implemented)
- should have a description (FAILED - 1)
- should have a title

Pending:
Product should have a valid image uri (Not Yet Implemented)

1)
'Product should have a description' FAILED
expected valid? to return false, got true
./spec/models/product_spec.rb:35:

Finished in 1.266 seconds

3 examples, 1 failure, 1 pending
rake aborted!
Command ruby -I
"C:/var/RSpec/depot/vendor/plugins/rspec/lib"
"C:/var/RSpec/depot/vendor/plugins/rspec/bin/spec"
"spec/models/product_spec.rb"
--options
"C:/var/RSpec/depot/config/../spec/spec.opts"
failed

C:/var/RSpec/depot/vendor/plugins/rspec/lib/spec/rake/
spectask.rb:173:in `define'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:823:in `verbose'
C:/var/RSpec/depot/vendor/plugins/rspec/lib/spec/rake/
spectask.rb:142:in `define'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:392:in `call'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:392:in `execute'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:392:in `each'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:392:in `execute'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:362:in `invoke'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:355:in `synchronize'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:355:in `invoke'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1739:in `top_level'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1739:in `each'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1739:in `top_level'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1761:in `standard_exception_handling'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1733:in `top_level'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1711:in `run'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1761:in `standard_exception_handling'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/
rake.rb:1708:in `run'
C:/usr/local/bin/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7
C:/usr/local/bin/ruby/bin/rake.bat:20:in `load'
C:/usr/local/bin/ruby/bin/rake.bat:20

C:\var\RSpec\depot>
<---

-- 
***          E-Mail is NOT a SECURE channel          ***
James B. Byrne                mailto:ByrneJB at Harte-Lyne.ca
Harte & Lyne Limited          http://www.harte-lyne.ca
9 Brockley Drive              vox: +1 905 561 1241
Hamilton, Ontario             fax: +1 905 561 0757
Canada  L8E 3C3



More information about the rspec-users mailing list