NameError: uninitialized constant Parsers in RSpec

Related searches

I'm trying to test simple class in my Ruby 2.5.0 app:


module Parsers
  class JiraParser
    def initialize(event)
      payload = event['body']
      @event = JSON.parse(payload)

    def call
        reporter_email: reporter_email,
        reporter_name: reporter_name,
        ticket_number: ticket_number,
        description: description


    attr_reader :event

    def reporter_email
      event.dig('issue', 'fields', 'reporter', 'emailAddress')
# other methods from call are pretty much the same as `reporter_email`

With below specs:


require 'spec_helper'

RSpec.describe Parsers::JiraParser do
  describe 'call' do
    subject(:hash_creation) { }

    let(:reporter_name) { 'john.doe' }
    let(:reporter_email) { '' }
    let(:description) { 'This is a test description' }

    let(:event) do
        'body' => {
          'issue': {
            'key': 'TEST-Board-123',
            'fields': {
              'reporter': {
                'displayName': reporter_name,
                'emailAddress': reporter_email
              'description': description

    it { expect(hash_creation).to be_success }

But I've got an error:

NameError: uninitialized constant Parsers

./spec/source/parsers/jira_parser_spec.rb:5:in `' No examples found.

Should I add something to my rspec_helper to make it works? Right now it's pretty basic:

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true

  config.shared_context_metadata_behavior = :apply_to_host_groups

I understand this is just Ruby, no Rails, hence there's no magic involved. You need to make a source file available in spec file, so you have to put on the top something like:

require_relative '../../../source/parsers/jira_parser

rspec/rspec-rails, rb. Failure/Error: require File.expand_path('../config/environment', __dir__) NameError: uninitialized constant Parser::AST /home/� From the error: uninitialized constant Rspec (NameError) In your Cipher spec, you have misspelled RSpec as Rspec. Ruby identifiers are case-sensitive, and you haven't defined Rspec, hence the error. Rspec-rails - Uninitialized constant Rspec

Hello I am still pretty new so this might help but I believe that you need to require JiraParser

require 'jira_parser'
require 'jira_parser/parser'

This might work but the error is because you are trying to use a parser that is not accessible in your current code.

NameError: uninitialized constant JSON::Ext::Parser using jruby , NameError: uninitialized constant JSON::Ext::Parser using -bug/build/tmp/ jrubyExec/gems/rspec-core-3.1.7/lib/rspec/core/runner.rb:69 load at� This is a very basic question/issue, but I've attempted to get started with mutant/mutest several times over the years and always got stalled on something stupid. Would really appreciate any he

Ok I figured out - all I had to do was to add -I source inside the .rspec file to will load all tested classes. So in my case .rspec will look like below:


--require spec_helper
-I source

The Ruby NameError: Uninitialized Constant Error, The Ruby NameError: Uninitialized Constant error has several causes. Learn what they are and how to fix them with this helpful guide. The Uninitialized Constant error is a variation of a regular NameError exception class. It has several possible causes. You'll see this error when the code refers to a class or module that it can't find, often because the code doesn't include require, which instructs the Ruby file to load the class.

RSpec - uninitialized constant for instance double - api - csharp, I am getting a name error for a small API i am building with RSpec, using TDD parsed = JSON.parse(last_response.body) expect(parsed).to include(' expense_id': Sinatra end NameError: uninitialized constant ExpenseTracker:: API::Ledger� Hiding a constant temporarily removes it; it is restored to its original value after the test completes. FOO = 42 hide_const("FOO") FOO # => NameError: uninitialized constant FOO Like stubbed constants, names must be fully qualified. Hiding constants that are already undefined has no effect. hide_const("NO_OP") Topics. Stub Defined Constant

Changelog - RSpec Rails - RSpec, Stop unnecessarily loading rspec/core from rspec/rails to avoid IRB context warning. Switch to parsing params with Rack::Utils::parse_nested_query to match Rails. "uninitialized constant" errors are avoided when using using gems like� FOO = 7 describe "stubbing FOO" do it "can stub FOO with a different value" do stub_const("FOO", 5) FOO.should eq(5) end it "restores the stubbed constant when the example completes" do FOO.should eq(7) end end

Dismiss Join GitHub today. GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.

  • Ok but I have to test 40 classes, is there a way to change the settings to avoid adding each classes path every time?
  • Nope, I've got an error LoadError: cannot load such file -- parsers/jira_parser
  • did you try just using require_relative ? Also, did you check to make sure you have jira_parser installed