【问题标题】:Running rspec test in RubyMine gets `bin/rspec:2: `$(' is not allowed as a global variable name`在 RubyMine 中运行 rspec 测试得到 `bin/rspec:2: `$(' is not allowed as a global variable name`
【发布时间】:2016-09-29 02:19:06
【问题描述】:

我有一个测试控制器的 rspec 文件。

当我右键单击此 rspec 文件并为我所在的文件选择 Run / Debug 时,它会在控制台中显示以下内容:

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

我的 bin/rspec 文件有两行 bash 脚本:

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

所以 ruby​​mine(或 rspec?不确定)正在解释 bash 脚本,就好像它是 ruby​​ 一样。为什么会这样?如何修复它以便调试文件?

--编辑:--

如果有帮助,这里是规范文件。

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: 'invalidemail@mail.com', 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: 'justin.eisenhauer@metova.com', 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: 'justin.eisenhauer@metova.com', password: 'metova' }
      expect(response.status).to eq(200)
    end
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby rspec rubymine


    【解决方案1】:

    对于任何有同样问题的人......我最终做的是,我的一个朋友让我将 rspec 重命名为 rspec.rb,这样它实际上可以作为 ruby​​ 运行。然后将其内容更改为:

    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      相关资源
      最近更新 更多