I would like to specify a base URL so I don’t have to always specify absolute URLs. How can I specify a base URL for Mechanize to use?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To accomplish the previously proffered answer using Webrat, you can do the following e.g. in your Cucumber env.rb:
To make it more robust, such as for use in different environments, you could do:
Note that if you’re using Mechanize, Webrat will also fail to follow your redirects because it won’t interpret the current host correctly. To work around this, you can add
session.header('Host', ENV['CUCUMBER_HOST'])to the above.To make sure the right paths are being used everywhere for visiting and matching, add
ENV['CUCUMBER_BASE_PATH'] +to the beginning of your paths_to method in paths.rb, if you use it. It should look like this:Apologies if anyone got a few e-mails from this — I originally tried to post as a comment and Stack Overflow’s irritating UI got the better of me.