小编jpa*_*eri的帖子

使用Rspec测试Devise时,"setup_controller_for_warden"错误中的"未定义方法`env'为nil:NilClass"

我正在尝试通过使用factorygirl创建用户创建一个注销流程规范,然后使用Devise的sign_in方法对用户进行身份验证,然后使用capybara单击"注销"链接.

当我运行规范时,我得到(在我看来是什么)一个奇怪的错误:

Failures:

  1) Sign out flow successfully redirects to the welcome index (root)
     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `env' for nil:NilClass
     # /home/vagrant/.rvm/gems/ruby-2.0.0-p576/gems/devise-3.4.1/lib/devise/test_helpers.rb:24:in `setup_controller_for_warden'

Finished in 0.00226 seconds (files took 3.32 seconds to load)
1 example, 1 failure
Run Code Online (Sandbox Code Playgroud)

这是规格:

require 'rails_helper'

describe "Sign out flow" do

  include Devise::TestHelpers

  describe "successfully" do
    it "redirects to the welcome index (root)" do
      user = create(:user)
      sign_in user


      within '.user-info' do
        click_link 'Sign Out'
      end …
Run Code Online (Sandbox Code Playgroud)

rspec devise capybara ruby-on-rails-4 factory-bot

39
推荐指数
6
解决办法
2万
查看次数

如何在Go模板中迭代特定次数?

我正在将 erb 模板转换为 Go 模板(使用 Hugo),并且尝试创建特定数量的相同<div>s。Ruby 有times迭代器,它在 erb 模板中运行良好。我认为 Go 中也有类似的东西,但我很难找到它。

在埃尔布:

<% 100.times.each do |i| %>
  <div class='star'></div>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我发现 Go 模板允许使用 迭代集合range,但不清楚如何在 Go 模板中执行上述操作而不显式创建包含 100 个项目的集合。

这个问题有一些关于在 Go 中迭代特定次数的信息,但不在 Go 模板的上下文中: Is there a way to iterate over a range of integers in Golang?

go hugo

5
推荐指数
1
解决办法
2866
查看次数

Bundler 找不到 rspec 可执行文件

当我尝试在 Rails 5.1 应用程序中运行测试时,出现无法找到可执行文件的错误:

$ bundle exec rspec
bundler: failed to load command: rspec (/Users/joepalmieri/.rbenv/versions/2.3.3/bin/rspec)
Gem::Exception: can't find executable rspec
  /Users/joepalmieri/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/rubygems_integration.rb:408:in `block in replace_bin_path'
  /Users/joepalmieri/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/rubygems_integration.rb:434:in `block in replace_bin_path'
  /Users/joepalmieri/.rbenv/versions/2.3.3/bin/rspec:22:in `<top (required)>'
Run Code Online (Sandbox Code Playgroud)

但是,当我查看时/Users/joepalmieri/.rbenv/versions/2.3.3/bin,可执行文件在那里:

$ ls /Users/joepalmieri/.rbenv/versions/2.3.3/bin | grep rspec
// => rspec
Run Code Online (Sandbox Code Playgroud)

以下是我的 Gemfile 的相关部分:

gem 'rails', '~> 5.1.4'

group :development, :test do
  gem 'rspec-rails', '3.7.2'
end
Run Code Online (Sandbox Code Playgroud)

跑步rbenv rehash没有帮助。

关于我为制造这种疯狂所做的愚蠢事情有什么线索吗?

ruby rspec ruby-on-rails bundler

4
推荐指数
1
解决办法
2170
查看次数

rake错误:"警告:已初始化常量FileUtils :: OPT_TABLE"

我已经看到有关此错误的类似问题,但所有这些都与rails有关.我没有使用铁轨; 我正在研究一个从yaml文件读取的本地rake任务,然后处理数据.我宁愿不为此安装bundler(类似rails问题的解决方案建议在前面加上bundle exec),因为这个脚本很简单,因此不需要它.

这是简化的代码(它得到与我正在处理的代码相同的错误):

require 'FileUtils'
require 'yaml'

SOME_FILE = "#{Dir.pwd}/some_file.yaml"

task default: :foo

task :foo do
  bar = File.open(SOME_FILE) { |yf| YAML::load( yf ) }
  bar.each {|k,v| puts k}
end
Run Code Online (Sandbox Code Playgroud)

这是错误列表:

/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/FileUtils.rb:93: warning: already initialized constant FileUtils::OPT_TABLE
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/fileutils.rb:93: warning: previous definition of OPT_TABLE was here
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/FileUtils.rb:1272: warning: already initialized constant FileUtils::Entry_::S_IF_DOOR
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/fileutils.rb:1272: warning: previous definition of S_IF_DOOR was here
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/FileUtils.rb:1535: warning: already initialized constant FileUtils::Entry_::DIRECTORY_TERM
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/fileutils.rb:1535: warning: previous definition of DIRECTORY_TERM was here
/Users/jpalmieri/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/FileUtils.rb:1537: warning: already initialized …
Run Code Online (Sandbox Code Playgroud)

ruby rake ruby-2.0

1
推荐指数
1
解决办法
4843
查看次数