ruby-on-rails - 在 RubyMine 中运行 rspec 测试得到 `bin/rspec:2: ` $ (' is not allowed as a global variable name`

标签 ruby-on-rails ruby rspec rubymine

我有一个测试 Controller 的 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

最佳答案

对于任何有同样问题的人...我最终做的是,我的一个 friend 告诉我将 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')

关于ruby-on-rails - 在 RubyMine 中运行 rspec 测试得到 `bin/rspec:2: ` $ (' is not allowed as a global variable name`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39712492/

相关文章:

ruby-on-rails - Kaminari & Rails 分页 - 未定义的方法 `current_page'

mysql - 在 Ruby on Rails 中从数组中删除具有列值的记录

ruby-on-rails - 使用 Puma 的 SSL、HTTP 解析错误、格式错误的请求

ruby-on-rails - 使用销毁的对象将 ActiveJob 任务排入队列

ruby - Ruby 的 dup 和 clone 方法有什么区别?

ruby-on-rails - 如何拥有可维护的用户名黑名单

ruby-on-rails - 事件模型序列化器中的条件属性

ruby-on-rails - Rspec:检查系统调用的内容

ruby-on-rails - Rake 12.3 仍然产生 NoMethodError : undefined method 'last_comment'

ruby - rspec:第一次失败后如何继续测试