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

  • Home
  • SEARCH
  • 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 6374491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:29:42+00:00 2026-05-25T01:29:42+00:00

I’m using RSpec for tests and I don’t know how to get this to

  • 0

I’m using RSpec for tests and I don’t know how to get this to green.

In this case, I have a model called “PartType” that holds an attribute called “quotation”.

The value for quotation comes from a form, so it will be a string.

To demonstrate you can go to console and type:

(1..1000).includes?("50") # false

but..

(1..1000).includes?(50) # true

And this value can have decimals. So I needed to do a “type_cast”.

I have this on my PartTypemodel:

before_validation :fix_quotation, :if => :quotation_changed?

protected
  def fix_quotation
    self[:quotation] = quotation_before_type_cast.tr(' $, ' , '.' )
  end

This are working as expected BUT when go to tests, it fails.

Here is my part_type_spec.rb:

require 'spec_helper'

describe PartType do

  before(:each) do
    @attr = { :title => "Silver", :quotation => 100 }
  end

  it "should create a instance given a valid attributes" do
    PartType.create!(@attr)
  end

  it "should accept null value for quotation" do
    PartType.new(@attr.merge(:quotation => nil)).should be_valid
  end

  it "should accept 0 value for quotation" do
    PartType.new(@attr.merge(:quotation => 0)).should be_valid
  end

end

And finally the failing tests:

Failures:

1) PartType should create a instance given a valid attributes
Failure/Error: PartType.create!(@attr)
NoMethodError:
undefined method tr' for 100:Fixnum
# ./app/models/part_type.rb:7:in
fix_quotation’
# ./spec/models/part_type_spec.rb:10:in `block (2 levels) in ‘

2) PartType should accept 0 value for quotation
Failure/Error: PartType.new(@attr.merge(:quotation => 0)).should be_valid
NoMethodError:
undefined method tr' for 0:Fixnum
# ./app/models/part_type.rb:7:in
fix_quotation’
# ./spec/models/part_type_spec.rb:18:in `block (2 levels) in ‘

Finished in 0.06089 seconds
3 examples, 2 failures

  • 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-25T01:29:42+00:00Added an answer on May 25, 2026 at 1:29 am
    1. Your include? snippets are wrong, I got false in the first, true in the second.
    2. before_validation is executed and quotation_before_type_cast is expected to be a String but it is a Fixnum. Change 100 to '100' and 0 to '0'.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.