嗨我已经安装了Pry来做一些很棒的调试并且之前有它工作但是当我用'next'进入代码时我得到以下错误:
SyntaxError: (eval):2: Can't escape from eval with next
Run Code Online (Sandbox Code Playgroud)
正在使用的代码:
def create
binding.pry
build_resource(sign_up_params)
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
Run Code Online (Sandbox Code Playgroud)
其他人遇到过这个问题吗?
我期待在执行期间在我的控制台中打开一个pry会话rspec.我做错了吗?或者期待错误的行为?
的Gemfile:
group :development, :test do
gem 'rspec'
gem 'rspec-rails'
...
gem 'pry-rails'
...
end
Run Code Online (Sandbox Code Playgroud)
Gemfile.lock的:
...
pry (0.10.0)
...
rspec-rails (3.0.1)
Run Code Online (Sandbox Code Playgroud)
规格:
require 'rails_helper'
RSpec.describe Account, type: :model, do
let!(:acct) { FactoryGirl.create(:account) }
describe '#hash' do
it 'should ...' do
acct.property = 5
binding.pry
expect(acct).to_not be_nil
end
end
end
Run Code Online (Sandbox Code Playgroud)
安慰:
% rspec
...
Failed examples:
...
Randomized with seed 59654
Run Code Online (Sandbox Code Playgroud) 我很困惑需要安装哪些宝石才能在Rails 4.2项目中正确运行Pry.直到最近我似乎都很好.出于某种原因,binding.pry现在看来咯出每当我试图通过一个控制台会话步骤next,step在命令行,等等.它将抛出一个丑陋的堆栈跟踪,然后在代码中向我显示相同的点,而不会进一步踩踏.在第二个next命令之后,它会抛出相同的堆栈跟踪并退出,从而将执行返回到localhost服务器.我在浏览器页面上遇到运行时错误No frames collected.
如果我binding.pry在我的代码中注释掉,一切正常.所以我强烈怀疑我的Pry配置有问题.似乎Pry有几十种变体,没有明确的指导应该安装哪一个,哪些可能会发生冲突,等等.
这是next代码到达binding.pry调用后在Pry控制台中调用时得到的堆栈跟踪:
From: /Users/me/sites/arailsapp/app/controllers/bars_controller.rb @ line 31 BarsController#edit:
29: def edit
30: binding.pry
=> 31: @bar = Bar.find(params[:id])
32: @foo = @bar.foo
33: end
[6] pry(#<BarsController>)> n
Completed 500 Internal Server Error in 2685ms (ActiveRecord: 0.0ms)
RuntimeError - No frames collected.:
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:122:in `perform_next'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:60:in `perform'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:49:in `run'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:111:in `resume_pry'
pry-byebug (3.2.0) lib/byebug/processors/pry_processor.rb:69:in …Run Code Online (Sandbox Code Playgroud) 假设我们已经pry安装,打开rails控制台,然后运行
times = [1, 5, 10, 30, 72].sample(1)[0]
nums = *(1..72)
num_sample = nums.sample(times)
Run Code Online (Sandbox Code Playgroud)
计算在第 2 行之后停止(因为第二行的输出超出屏幕,因此控制台打开输出):
如何才能让控制台不停止执行,而是在执行下一行之前显示一行的全部输出,即执行它收到的所有代码行?有没有什么方法可以在不移除撬轨宝石的情况下实现这一目标?
我目前正在为Rails控制器编写规格。我似乎无法获得任何puts语句或binding.pry或binding.remote_pry。
我能够在开发环境中使远程撬动工作。
group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'capybara'
gem 'factory_girl_rails'
gem 'daemons'
gem 'pry-rails'
gem 'pry-remote'
gem 'binding_of_caller'
end
Run Code Online (Sandbox Code Playgroud) 不久前我发现了 Pry,但我不喜欢 Pry 的几个方面
是否可以在 pry 和 IRB 之间进行实时切换?在调试方面我喜欢 pry,但在效率/复制粘贴方面,IRB 仍然是一流的。
所以我在寻找
(我的上下文正在运行一个 rails 控制台rails c)
任何提示?也许有一个环境变量可以让我选择两者之一?
我最近发现ls在 pry 中可以采用这样的参数:ls -l。
我最初的问题是该-l部分实际上是什么 - 它显然不是字符串或符号,并且没有l定义局部变量或方法,那么幕后是否还有其他事情发生?
作为我的问题的扩展,只是lspry 定义的“正常”Ruby 方法,还是它的行为略有不同?
我还注意到,如果传递字符串 ( ls 'l') 或符号 ( ls :l),您会得到不同的输出。是否有可能选项的完整参考?
当我在我当前的笔记本电脑上使用rails控制台时(在任何rails项目上),当控制台启动时出现以下错误.
Rails console error: Error loading ~/.pryrc: Command: `continue` not found
Run Code Online (Sandbox Code Playgroud)
控制台仍然正常加载和运行,但我似乎无法弄清楚错误的原因.
这是.pryrc的内容.
Pry.config.pager = false
Pry.config.color = true
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Run Code Online (Sandbox Code Playgroud)
如果我删除第三行并运行rails控制台,错误我得到一个类似的错误,引用'step'代替.该错误不会影响我的故障排除能力,但我真的很想了解潜在的问题.
我不熟悉 Ruby,但无论如何我都在尝试安装和测试 iQvoc ( https://github.com/innoq/iqvoc )。在一些最初的问题之后,我设法用 heroku 安装了它。我现在正在尝试导出一个小的测试同义词库,但我在使用 Ruby 时遇到了一些问题。我使用这个命令:
rake --trace iqvoc:export TYPE=ttl NAMESPACE='http://namespace.example.fr/'
Run Code Online (Sandbox Code Playgroud)
结果如下:
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'pry-rails'.
Gem Load Error is: uninitialized constant Pry::Prompt
Backtrace for gem load error is:
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/pry-rails-0.3.5/lib/pry-rails/prompt.rb:36:in `<module:PryRails>'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/pry-rails-0.3.5/lib/pry-rails/prompt.rb:1:in `<top (required)>'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/pry-rails-0.3.5/lib/pry-rails.rb:10:in `<top (required)>'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `require'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `each'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:86:in `block in require'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `each'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:75:in `require'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.6/lib/bundler.rb:107:in `require'
/home/nicola/iqvoc_2/config/application.rb:23:in `<top (required)>'
/home/nicola/iqvoc_2/Rakefile:20:in `require'
/home/nicola/iqvoc_2/Rakefile:20:in `<top (required)>'
/home/nicola/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/rake-12.0.0/lib/rake/rake_module.rb:28:in …Run Code Online (Sandbox Code Playgroud)