如何在Capybara中使用同步?

如果使用wait_until非常清楚(我在使用本机Webdriver方法创建测试时使用了这样的方法),而不是新的同步方法(抱歉:))。 我已经阅读了关于为什么不推荐使用wait_until的主题,我已经阅读了有关该文章的文章,我已经阅读了带有方法描述的文档,并且还阅读了描述所在的代码。 但我没有找到任何示例或教程如何使用此方法。 请允许任何人提供我(也可能是其他人)可以看到并学习如何使用此方法的少数情况 例如案例 expect(actual).to equal(expected) 我应该在哪里“放”同步方法才能在超时过后获得负面exception? UPD:对于有兴趣的人请查看以下链接: http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara https://github.com/jnicklas/capybara/blob/master/lib/capybara/node/base.rb#L44

Mongoid和ActiveRecord关系:未定义的方法`quoted_table_name’

class Contest NoMethodError: undefined method `quoted_table_name’ for ClaimTemplate:Class 好的,我们将quoted_table_name添加到ClaimTemplate : def self.quoted_table_name “claim_templates” end # console Contest.new.claim_template #=> nil # Cool! # But: Contest.last.claim_template #=> TypeError: can’t convert Symbol into String 那么如何配置我的模型以便彼此正常工作 PS: 现在我有这种结构,工作正常,但我希望获得关系( Assosiations )的好处。 class Contest self.id).first end # Mongoid going to be crazy without this hack def self.using_object_ids? false end end

从Rails模型中访问current_user?

我正在构建一个基本遵循以下模式的Invoicing应用程序: Users < Clients < Projects < Invoices 现在,为了为每个用户生成自动递增发票号,我将其放入我的Invoice模型中: before_create :create_invoice_number def create_invoice_number val = @current_user.invoices.maximum(:number) self.number = val + 1 end 但是,似乎无法从Rails中的模型中访问current_user变量? 我该怎么做才能解决这个问题?

在两个单独的页面上刮取需要登录用户名和密码的站点

我正试图从我公司的Intranet中获取信息,这样我就可以通过仪表板在我们的办公室墙板上显示信息。 我正在尝试使用以下提供的信息: 本网站 。除了作为菜鸟之外,我遇到的问题是,为了获取我想要抓取的信息,我需要登录我们的Intranet提供我的用户名在一个页面上,然后提交给另一个,以便我可以提供我的密码。 一旦我登录,我就可以链接并抓取我的数据。 以下是我的登录用户名页面中的一些源代码:  Username: 2) { submit(); } else { alert(‘Enter your Username.’); }”> 以下是我的登录密码页面的一些来源:  Password: 2) { submit(); } else { alert(‘Enter your Password.’); }”> 使用所述资源的示例这是我认为应该工作但似乎不是: require ‘mechanize’ @agent = Mechanize.new @agent.verify_mode = OpenSSL::SSL::VERIFY_NONE ##Login Page: page = @agent.get ‘http://www.website_here.com/intranet/login.asp’ ##Username Page: form = page.forms[0] form[‘USER NAME HERE’] = LoginUser ##Submit […]

为什么我不能得到rake db:迁移到ruby.railstutorial.org工作

我决定通过这个教程。 在我创建一个新的应用程序并添加新user:string email:string然后在app目录中执行rake db:migrate之后,我得到了这个输出: rake aborted! undefined method `task’ for # /usr/local/rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks’ /usr/local/rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks’ /usr/local/rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing’ /Users/zigloo99/rails_projects/demo_app/Rakefile:7:in `’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load_rakefile’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:495:in `raw_load_rakefile’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:78:in `block in load_rakefile’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:129:in `standard_exception_handling’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:77:in `load_rakefile’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:61:in `block in run’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:129:in `standard_exception_handling’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/lib/rake/application.rb:59:in `run’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.0/bin/rake:31:in `’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/bin/rake:19:in `load’ /usr/local/rvm/gems/ruby-1.9.2-p180@global/bin/rake:19:in `’ 我正在使用RVM太ruby 1.9.2和rails 3.0.7,如教程中所示。 有什么想法吗?

我可以在播种时将所有产品更新到特定用户吗?

如何更新所有产品以将特定用户分配给他们? admin = User.create(:name => “Admin”, :password => “password”) walmart = Store.create(:name => ‘Walmart’, :address => ‘San Francisco, Palo Alto’) walmartprices = walmart.products.create ([ {:name => “Rice”, :price => ‘5.93’}, {:name => “Chicken”, :price => “2.24”}, {:name => “Milk”, :price => ‘3.81’}, {:name => ‘Eggs’, :price => ‘2.78’} ]) walmartprices.update_attribute(:user => admin) 当然这给了我一个错误: undefined method […]

Bundler:如何在没有导轨的情况下使用?

我有一个项目使用铁路外的黄瓜。 如何使用我的gemfile中指定的版本加载gem?

收集不必要分配给任何变量/常量的对象

未分配给任何变量/常量的对象立即消失(在正常情况下)。 在下面,第三行中的ObjectSpace.each_object(String)不捕获字符串”foo” : strings = ObjectSpace.each_object(String).to_a “foo” ObjectSpace.each_object(String).to_a – strings # => [] 是否有可能捕获不必分配给任何变量/常量或任何变量/常量的一部分的对象? 我对捕获字符串特别感兴趣。 相关域可以是文件或块。 我希望如下: capture_all_strings do … “a” s = “b” @s = “c” @@s = “d” S = “e” %q{f} … end # => [“a”, “b”, “c”, “d”, “e”, “f”]

在我的gem里面使用捆绑器

我想在我写的gem中使用bundler。 我有Gemfile和my_gem_file.rb我有 require ‘rubygems’ require ‘bundler’ Bundler.setup Bundler.require(:default) 但是当我构建并安装我的gem时,我得到exceptionBundler :: GemfileNotFound:找不到Gemfile。 在gem中使用捆绑器有什么解决方案吗?

在使用RSpec测试控制器时模拟CanCan授权

这是我要测试的控制器: class UsersController < ApplicationController load_and_authorize_resource def index @users = User.all respond_to do |format| format.html # index.html.erb format.json { render json: @users } end end def show @user = User.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @user } end end #other actions here end 如您所见,我使用CanCan方法load_and_authorize_resource因此我为RSpec编写了一个ControllerHelper: # spec/support/controller_spec.rb module ControllerHelper def should_authorize(action, […]