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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:39:27+00:00 2026-06-07T23:39:27+00:00

I have the following spec: describe EmailImport do describe #format_x_priority do specify { EmailImport.format_x_priority(‘5

  • 0

I have the following spec:

describe EmailImport do
  describe "#format_x_priority" do
    specify { EmailImport.format_x_priority('5 (Lowest)').should eq(:low) }

    it "should raise an error when wrong argument is passed" do
      expect { EmailImport.format_x_priority('5 (Lowest)').to raise_error }
    end
  end
end

This should not pass, right? It’s both times the same code, and one time it should result in :low, and one time it should result in an error. But interestingly, both pass! What am I doing wrong?

Just for the sake of completeness, here’s my EmailImport.format_x_priority method:

def self.format_x_priority(priority)
  # 1 Highest; 2 High; 3 oder "" normal; 4 low; 5 lowest
  case priority
  when "1 (Highest)"
    Priority::HIGH
  when "2 (High)"
    Priority::HIGH
  when "3 (Middle)"
    Priority::MEDIUM
  when "4 (Low)"
    Priority::LOW
  when "5 (Lowest)"
    Priority::LOW
  when ''
    Priority::MEDIUM
  else
    raise "Invalid value '#{priority}' for argument 'priority'!"
  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-07T23:39:29+00:00Added an answer on June 7, 2026 at 11:39 pm

    Syntax Error

    You have a syntax error. You’re enclosing the entire line, including the matcher, in the block. Move the curly brace to enclose just the lambda, and you should be back on track. For example:

    it "should raise an error when wrong argument is passed" do
      expect { EmailImport.format_x_priority('5 (Lowest)') }.to raise_error
    end
    

    Why This Works

    The specify keyword takes a block, so specify { ... } is correct. On the other hand, expect takes a lambda, and passes it to the matcher. That makes expect { ... }.to raise_error correct.

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

Sidebar

Related Questions

I have following spec to test controller method: context #create do it should redirect
Currently in my spec/decorators/product_decorator_spec.rb, I have the following: require 'spec_helper' describe ProductDecorator do let(:product)
I have the following rspec: require 'spec_helper' describe KnowledgesController do before (:each) do @knowledge
I have the following spec: it saves a default 'active' status if not specified
Running rails 3.2.3 with guard/spork/rspec/factory_girl and have the following in my spec helper: Spork.prefork
In a branch spec, I have the following view: //depot/dev/t/a/g/... //depot/dev/t/r/g/... -//depot/dev/t/a/g/p/o*/... //depot/dev/t/r/g/p/... Perforce
I have tree with the following node spec: java.util.TreeMap<Long id, java.util.TreeMap children> When I
I have the following XML example: <?xml version=1.0 encoding=UTF-8?> <OpenSearchDescription xmlns=http://a9.com/-/spec/opensearch/1.1/ xmlns:custom=http://example.com/opensearchextensions/1.0/> <ShortName>Test</ShortName> <Description>Testing....</Description>
I have the following rspec code: require 'spec_helper' require 'mocha' require 'rr' describe ProjectsController,
I´m testing my rails app using rspec and remarkable. I have the following spec

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.