Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4088628
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:00:25+00:00 2026-05-20T19:00:25+00:00

I am trying an rspec test where the example looks like so: it cannot

  • 0

I am trying an rspec test where the example looks like so:

it "cannot be deleted if it has children" do
  children = generate_children
  children.each do |child|
    child.parent = @subj
    @subj.save
    child.save
    @subj.destroy.should be_false
    @subj.should have(1).error
   end
end

I get this in the backtrace:

/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/handler.rb:21:in `handle_matcher'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-expectations-2.5.0/lib/rspec/expectations/extensions/kernel.rb:27:in `should'
./spec/models/my_examples.rb:14
./spec/models/my_examples.rb:10:in `each'
./spec/models/my_examples.rb:10
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:49:in `instance_eval'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:49:in `run'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:106:in `with_around_hooks'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:46:in `run'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:99:in `with_pending_capture'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `catch'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98:in `with_pending_capture'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:45:in `run'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:262:in `run_examples'
/opt/tms/bin/jruby-1.5.1/lib/ruby/gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:258:in `map'

But the test passes, although with the ugly backtrace shown above.
Any idea how I could rewrite this test / am I doing something wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:00:26+00:00Added an answer on May 20, 2026 at 7:00 pm

    line14 is the destroy-line – which is interesting.

    According to the source code, destroy doesn’t return true/false – it returns the same item (through freeze).

    I don’t think you’re expected to check if it was “true”. It’s probably failing because an frozen Active Record isn’t false… but it’s kind of a weird thing to compare with.

    Not sure how you’d go about checking it…perhaps with the equivalent of

    lambda do @subj.destroy end.should_not change(Subject, :count).by(-1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to expect an error in an rspec test. lambda {Participant.create!({:user_id => three.id,
I'm trying to perform an integration test via Watir and RSpec . So, I
I'm new to rails and I'm trying to test a controller with rspec. My
I am trying to capture screenshots on test failure using selenium-client and rspec. I
RSpec newbie here. I'm trying to test my models, which have methods that uses
I'm trying to learn RSpec and writing test for CRUD actions. Here is my
I am trying to test my views with RSpec. The particular view that is
I'm trying to use RSpec to test a Rails 3.1rc4 project. I want to
Upgraded form Rails 2 to 3. And RSpec 1 to 2. It looks like
I have a ruby script I'm trying to test with rspec. Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.