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 9174425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:45:20+00:00 2026-06-17T16:45:20+00:00

Is it possible to test the pluralize function in rspec? let(:schedule) { FactoryGirl.create(:schedule) }

  • 0

Is it possible to test the pluralize function in rspec?

let(:schedule) { FactoryGirl.create(:schedule) }

Failure/Error: it { should have_selector('h1', text: pluralize(Schedule.count.to_s, "schedule")) }
 NoMethodError:
   undefined method `pluralize' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xb607068c>

ANSWER: (as pointed by Eric C below)

describe SchedulesHelper do
  describe "pluralize schedule" do
    if(Schedule.count > 0)
        it { pluralize(1, "schedule").should == "1 schedule" }
    else
        it { pluralize(0, "schedule").should == "0 schedules" }
    end    
  end 
end
  • 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-06-17T16:45:21+00:00Added an answer on June 17, 2026 at 4:45 pm

    The answer to your question is… sort of. Rails provides the functionality to use pluralize and using rspec-rails, assuming that’s what you are using, gives you the ability to call on rails methods as you need them. If this is a view test, which is sort of what it looks like, you can type something like:

    it { should have_selector('h1', text: view.pluralize(Schedule.count.to_s, "schedule")) }
    

    The key here is that you’re adding the view. before pluralize.

    I would like to stress that when testing, it’s not a great idea to test a helper method inside what appears to be a view test. If you’d really like to test pluralize itself, it’d be better to test it in a helper spec. Doing something like:

    it { pluralize(1, "schedule").should == "1 schedule" }
    it { pluralize(0, "schedule").should == "0 schedules" }
    

    This way you can be assured of the outcome and make assumptions in other tests and then test the proper outcome. It actually will inevitably make the tests better, because if a helper like pluralize changes then you have two tests that alarm of this change. You then can adjust accordingly. Just a thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do you test that a Python function throws an exception? I
I'm trying to create a regex so I can identify URLs in text. Possible
Possible Duplicate: Test if a Font is installed let say Im using an installed
Is it somehow possible to test warnings i Ruby using RSpec? Like this: class
In Rails testing with RSpec and Capybara, is it possible to test the position
Is it possible to test existance of js function in page using Capybara? if
Is it possible to test for multiple exceptions in a single JUnit unit test?
Is it possible to test for enum equality in JSF? E.g. where stuff is
Possible Duplicate: Interesting test of Javascript RegExp Regular expression test can't decide between true
Is it possible to JUnit test if wiring by Spring is succesfully? I would

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.