我正在研究我的第一个Ruby gem,并将黄瓜,rspec和shoulda-matches捆绑在一起进行测试.当我运行rspec时,我收到以下错误:
/app/my_gem/spec/spec_helper.rb:6:in `<top (required)>': undefined method `configure' for Shoulda::Matchers:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
这是我的gemspec:
# my_gem.gemspec
...
Gem::Specification.new do |spec|
...
...
spec.add_development_dependency "activemodel"
spec.add_development_dependency "bundler", "~> 1.8"
spec.add_development_dependency "cucumber"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "shoulda-matchers"
end
Run Code Online (Sandbox Code Playgroud)
我的spec_helper.rb:
require 'my_gem'
require 'pry'
require 'shoulda/matchers'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
# with.library :active_record
with.library :active_model
# with.library :action_controller
# Or, choose all of the above:
# with.library :rails
end
end
Run Code Online (Sandbox Code Playgroud)
.configure由于某些原因,它发现了Shoulda :: Matchers而不是方法.我shoulda以某种方式要求错误吗?不确定这是否相关,但是rspec也给了我这个警告: …
我正在使用GitHub中的wiki,并希望使用较短的链接链接到repo中的文件.我发现如果我使用这里描述的普通相对链接方法,链接是相对于wiki的,即它试图在wiki中找到具有该名称的页面,而GitHubs文档和博客中描述的相对链接是假设链接在README中.
有没有办法使用维基中的缩短链接到回购中的文件,还是必须使用完整链接?
我在必要时使用Stripe API Reference实现Stripe Connect API .使用该引用我无法解决两个问题:
1)是否可以删除银行账户?如果是这样,怎么样?我已经打过电话标准delete和destroy银行账户对象的方法,以及.destroy_all上account.bank_accounts.account.bank_accounts.first = nil似乎也没有用.
2)是否可以添加多个银行账户?父Account对象有一个.bank_accounts这样的事实使它看起来应该是可能的,但我能找到添加银行帐户的唯一方法是account.bank_account=允许您创建或更新单个帐户.
我有一个 PR 合并到 GitHub 上一个开源项目的 master 分支。该项目不是分叉,如果我在 PR 中编辑的主树中查看文件,我会在那里被列为该文件的贡献者。
然而,出于某种原因,我没有出现在项目的主要“贡献者”页面中。有谁知道为什么会这样?我已经查看了这个 GitHub 帮助页面,关于在我自己的个人资料中显示的贡献,但我的问题是关于在实际项目的“贡献者”页面中显示。
作为参考,这里是有问题的 PR:https : //github.com/octokit/octokit.rb/pull/780
我正在使用cobra构建 CLI 并希望模拟使用不同选项/标志集运行的命令。我一直试图弄清楚如何使用眼镜蛇 API 在我的测试中设置标志,但还没有真正得到它。
我有这个:
// NewFooCmd returns a cobra.Command fitted to print output to the buffer for easier testing.
buf := &bytes.Buffer{}
cmd := package.NewFooCmd(buf)
cmd.Execute()
// some validations on the content of buf
Run Code Online (Sandbox Code Playgroud)
到目前为止,我发现的最接近的是:
cmd.Flags().Set(name string, value string)
...但这似乎不正确,因为虽然标志的名称都是字符串,但它们并不都将字符串作为值。此外,即使我有intflag 和 pass ,它似乎也不起作用string(1)。
我在这里遗漏了一些简单的东西吗?
在构建 docker 镜像时,由RUN命令引起的错误会打印到 stdout 而不是 stderr。例如:
如果我flooby在我的 shell 上运行命令,由于找不到命令而失败的事实会打印到 stderr:
$ flooby 2> err.log
$ cat err.log
bash: flooby: command not found
Run Code Online (Sandbox Code Playgroud)
但是,如果我正在构建一个包含该行的 Docker 映像RUN flooby,尽管(可能)在容器/映像/正在构建的任何内容中,错误将打印到 stderr,docker 将其打印到 stdout:
$ docker build -t stderr-test . 2> err.log
Sending build context to Docker daemon 121.1MB
Step 1/2 : FROM ruby:2.6
---> d98e4013532b
Step 2/2 : RUN flooby
---> Running in 118f7d467b43
/bin/sh: 1: flooby: not found
$ cat err.log
The command '/bin/sh -c flooby' returned …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有自动电子邮件提醒应用程序完成面试过程的下一步。电子邮件有一个选择退出链接,单击该链接时,应触发控制器操作,该操作会触发状态机事件以将其状态更改为opted_out。该链接不起作用,从本地主机控制台看来,这似乎是因为该链接仍在生成 GET 请求,而该请求没有路由(错误为ActionController::RoutingError (Not Found):)。
这是显示不需要的 GET 请求的控制台:
Started GET "/worker/application/opt_out.1" for 10.0.2.2 at 2014-08-29 17:08:06 +0000
Processing by LandingController#show as
Parameters: {"category"=>"worker/application", "location"=>"opt_out"}
Run Code Online (Sandbox Code Playgroud)
链接在这里:
link_to 'stop getting these reminders', opt_out_worker_application_url(@worker), method: :put, style: 'background-color: #fff; color: #56A0D3; display: inline-block; margin-bottom: 5px; margin: 0px; padding: 0px; text-decoration: none'
Run Code Online (Sandbox Code Playgroud)
以下是worker命名空间的所有路由:
# routes.rb
namespace :worker do
resource :application, only: [:create, :new, :show] do
member do
put 'opt_out' => 'application#opt_out'
end
end
resources :jobs do
member do …Run Code Online (Sandbox Code Playgroud) ActiveAdmin 文档解释了如何禁用分页并使用 来设置资源索引中每页的记录数config.per_page,但我想知道是否有一种内置方法允许用户per_page自己设置值,例如使用下拉列表?
settings pagination ruby-on-rails activeadmin drop-down-menu
我遇到了Minitest和相关ActiveRecord模型灯具的问题(Rails.4.2.3).
以下是两种型号:
# vanguard_fund.rb
class VanguardFund < ActiveRecord::Base
belongs_to :benchmark_fund
...
end
# benchmark_fund.rb
class BenchmarkFund < ActiveRecord::Base
has_many :vanguard_funds
end
Run Code Online (Sandbox Code Playgroud)
非常直截了当.现在这里是固定装置:
# vanguard_funds.yml
vf1:
name: Vanguard Fund 1
benchmark_fund: bm1
# benchmark_funds.yml
bm1:
name: Benchmark Fund 1
Run Code Online (Sandbox Code Playgroud)
现在我在运行任何测试时遇到以下错误:
ERROR["test_#name_returns_the_name_of_the_VanguardFund", BaseTest, 2015-06-08 13:39:28 +0000]
test_#name_returns_the_name_of_the_VanguardFund#BaseTest (1433770768.22s)
ActiveRecord::InvalidForeignKey: ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "vanguard_funds" violates foreign key constraint "fk_rails_994ab6fe75"
DETAIL: Key (benchmark_fund_id)=(479852872) is not present in table "benchmark_funds".
: INSERT INTO "vanguard_funds" ("name", "created_at", "updated_at", "id", "benchmark_fund_id") VALUES …Run Code Online (Sandbox Code Playgroud) 我在我的Rails 4应用程序中使用Devise进行用户身份验证.最近我在User模型中添加了两个新列.他们first_name然后last_name. 我用登录表单更新了这两个属性的字段.但是,在测试创建新用户时,两者都没有保存到数据库中.我认为这可能是一个质量分配问题,但我没有得到任何类型的数据库错误.用户已成功创建,但仅存储原始属性(email,password和password_confirmation).有人可以帮忙吗?
这是我的表单的代码:
<div class="row">
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="small-10 small-offset-0 columns">
<div class="row">
<div class="small-2 columns">
<%= f.label :first_name, class: 'right inline' %>
</div>
<div class="small-4 columns">
<%= f.text_field :first_name, id: 'right-label' %>
</div>
<div class="small-6 columns">
<!-- empty space -->
</div>
</div>
<div class="row">
<div class="small-2 columns">
<%= f.label :last_name, class: 'right inline' %>
</div>
<div class="small-4 columns">
<%= f.text_field :last_name, id: 'right-label' …Run Code Online (Sandbox Code Playgroud) 我在Rails 3.2应用程序中使用Devise进行身份验证,但是在配置omniauth-facebook获取新用户的电话号码时遇到麻烦。
首先:我什至不确定是否可以获取电话号码,因此,如果确实如此,并且有人可以肯定地知道,我很乐意接受确认。
尽管常规的Omniauth模式确实具有.info.phone(当然不是必需的),但从https://github.com/mkdynamic/omniauth-facebook看来,默认情况下“ phone”是FB auth哈希的一部分。 )。所以我的第一个想法是这是FB权限问题。不过,我不确定要使用什么权限,因为“ Facebook登录权限”页面没有说明在哪里可以找到电话值(也许这意味着不可能)。
我phone在用户模型上具有必填属性,因此当我尝试通过FB获取该属性时,新对象将永不持久。无需寻找电话号码即可正常工作。
我的配置文件:
# /config/initializers/devise.rb
config.omniauth :facebook, 'FACEBOOK_APP_ID', 'FACEBOOK_APP_SECRET', scope: 'email,public_profile', display: 'page'
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中:
# user.rb
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
user.first_name = auth.info.first_name
user.last_name = auth.info.last_name
user.phone = auth.extra.raw_info.phone # have also tried auth.info.phone
end
end
Run Code Online (Sandbox Code Playgroud)
预先感谢您可能提供的任何帮助!
我希望我的seeds.rb 文件有两个基于用户输入的路径。为了这个问题的简单起见,我将其精简为这两行:
print "> "
res = gets.chomp
Run Code Online (Sandbox Code Playgroud)
当我运行 rake db:seed 时,会引发以下异常:
? rake db:seed
> rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - db:seed
/home/me/work/my_app/db/seeds.rb:5:in `gets'
/home/me/work/my_app/db/seeds.rb:5:in `gets'
/home/me/work/my_app/db/seeds.rb:5:in `<top (required)>'
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么会发生这种情况,即为什么在这种情况下 get.chomp 导致程序尝试打开名为 db:seed 的文件?
ruby ×5
devise ×2
github ×2
hyperlink ×2
activeadmin ×1
cl ×1
cobra ×1
docker ×1
email ×1
facebook ×1
fixtures ×1
forms ×1
gem ×1
git ×1
go ×1
go-cobra ×1
http ×1
linux ×1
logging ×1
markdown ×1
minitest ×1
omniauth ×1
open-source ×1
pagination ×1
postgresql ×1
pull-request ×1
rspec ×1
settings ×1
shoulda ×1
stderr ×1
testing ×1