English 中文(简体)
在使用RSpec的Capybara时,如何以最佳方式确定习惯要求负责人?
原标题:What s the best way to set custom request headers when using Capybara in RSpec request specs?

I m monkey pading Capybara:Session with a set_headers means thatsigns to Capybara:Rack Test:Browser s Options Depende (The I ve change from an attr_reader to an attr_accessor).

www.un.org/Depts/DGACM/index_spanish.htm 传真:

class Capybara::RackTest::Browser
  attr_accessor :options
end

class Capybara::Session
  def set_headers(headers)
    if driver.browser.respond_to?(:options=) #because we ve monkey patched it above
      options = driver.browser.options
      if options.nil? || options[:headers].nil?
        options ||= {}
        options[:headers] = headers
      else
        options[:headers].merge!(headers)
      end
    else
      raise Capybara::NotSupportedByDriverError
    end
  end
end

www.un.org/Depts/DGACM/index_spanish.htm 在我的要求中,我做的是:。

page.set_headers("REMOTE_ADDR" => "1.2.3.4")
visit root_path

这种做法是可行的,但我很想知道,如果能以更好的方式行事,那么仅仅能够根据要求确定一种遥远的习惯。 任何想法?

问题回答

如果你希望全球所有要求都能够确定负责人,那么你可以采用这样的办法:

Capybara.register_driver :custom_headers_driver do |app|
  Capybara::RackTest::Driver.new(app, :headers => { HTTP_FOO  =>  foobar })
end

See rack_test_driver_spec.rb in Capybara 1.1.2 and Capybara s issue #320,

Do you need to add custom header into one specific request in rspec using capybara? I used this in acceptance tests. It was the best way for me to use get method with specific header data. You can assess specific element on response page. See my example below:

get user_registration_path, { :invite => invite_token }, {  X_GEOIP_COUNTRY_CODE  =>  US  } 
expect(assigns(:ip_country)).to eq( US )
response.body.should have_selector("input#currency_usd[checked= checked ]")

我希望它能够提供帮助。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签