开发者

[HTTP]how to change "www.example.com" to "localhost:3000"

hi I'm create test use cucumber in my rails apps. in my step scenario I used http basic authenticate, so far it pass the basic authenticate, but when I wanna to call method on controller and post some params, I had problem :

first I use this code in step but failed not cross to method on controller :

post some_admin_url, @params

second I used this code, and failed also, the error is when running the URI.parse redirect to "www.example.com" I want to go "localhost:3000/admin", so I can match the data :

Net::HTTP.post_form(URI.parse(some_admin_url), {'from' => '2005-01-01','to' => '2005-03-31'}) { |i|  }

FUTURE :

@selenium

Scenario: Admin want to activate user

Given one user logged in as admin

And admin page

STEPS :

Given /^one user logged in as admin$/ do

create_user_admin

visit '/user_sessions/new'

fill_in 'user_session[login]', :with=>'siadmin'

fill_in 'user_session[password]', :with=>'12345'

click_button 'Anmelden'

end

Given /^admin page$/ do

require "net/http"

require "uri"

uri = URI.parse(user_action_admin_users_url)<br/>
http = Net::HTTP.new(uri.host, uri.port)<br/>
request = Net::HTTP::Get.n开发者_开发百科ew(uri.request_uri)<br/>
request.basic_auth("username", "password")<br/>
response = http.request(request)<br/>

end

enter code here

HELP !!!

THANKS


fl00r's answer probably works, but wouldn't catch redirects. If you want to catch redirects you have to change this in a higher level. For some test frameworks there is a way to set the default host.

Using Capybara we did that:

Capybara.default_host = "subdomain.yourapp.local"

Now we actually use a Rack middleware (in test env only :), that changes changes the env[HTTP_HOST] transparently for the application, so we don't have to care about which testframework / browser driver we use.

What framework do you use?


uname="myapp"
Capybara.default_host = "http://#{uname}.mywebsite.com:3000"
Capybara.server_port = 3000 # could be any of your choice
Capybara.app_host = "http://#{uname}.mywebsite.com:#{Capybara.server_port}" 

OR

request.host="www.myapp.com"

,when you are extending ActionController::TestCase


try to change url to path

post some_admin_path, @params

or

post "http://localhost:3000/#{some_admin_url}", @params
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜