Search code examples
ruby-on-railsrubyrspecrubymine

Running rspec test in RubyMine gets `bin/rspec:2: `$(' is not allowed as a global variable name`


I have a rspec file that tests a controller.

When I right-click in this rspec file and select Run / Debug for the file I'm in, it shows the following in the console:

Fast Debugger (ruby-debug-ide 0.6.1.beta2, debase 0.2.2.beta8, file filtering is supported) listens on 0.0.0.0:64675
Uncaught exception: /develop/warranty-web/bin/rspec:2: `$(' is not allowed as a global variable name

Process finished with exit code 0

My bin/rspec file has two lines of bash script:

#!/usr/bin/env bash
exec $(dirname $0)/spring rspec "$@"

So rubymine (or rspec? not sure) is interpreting bash script as if it were ruby. Why is it doing this and how can I fix it so I can debug the file?

--Edit:--

If it helps, here is the spec file.

require 'spec_helper'
require 'ruby-debug'

describe Api::V1::Internal::SessionsController do
  before do
    @request.env['devise.mapping'] = Devise.mappings['api_v1_internal_user']
  end

  context 'when invalid email' do
    it 'returns a 401 (invalid credentials)' do
      post :create, user: { email: '[email protected]', password: 'madeuppassword' }
      expect(response.status).to eq(401)
    end
  end
  context 'when valid email but invalid password' do
    it 'returns a 401 (invalid credentials)' do
      post :create, user: { email: '[email protected]', password: 'madeuppassword' }
      expect(response.status).to eq(401)
    end
  end
  context 'when valid email and password' do
    it 'returns a 200 (ok)' do
      post :create, user: { email: '[email protected]', password: 'metova' }
      expect(response.status).to eq(200)
    end
  end
end

Solution

  • For anyone who has this same question...what I ended up doing was, a friend of mine showed me to rename rspec to rspec.rb so it can actually just be run as ruby. And then change it's contents to this:

    require 'pathname'
    ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
      Pathname.new(__FILE__).realpath)
    
    require 'rubygems'
    require 'bundler/setup'
    
    load Gem.bin_path('rspec-core', 'rspec')