I am trying to avoid using my session[:referred_by]
, and would like to use the request.referrer
. However, my RSpec tests fail because the TestRequest
does not store a request.referrer
So I have to do the following in order for Rspec tests to work. Is there a way to make it better:
referrer = request.referrer ? request.referrer : '/' redirect_to referrer, :alert => error_message
Installing RSpecBoot up your terminal and punch in gem install rspec to install RSpec. Once that's done, you can verify your version of RSpec with rspec --version , which will output the current version of each of the packaged gems. Take a minute also to hit rspec --help and look through the various options available.
RSpec is a testing framework written in Ruby to test Ruby code. To get started using RSpec with Rails, add it to the Gemfile. group :development, :test do gem 'rspec-rails' end. Next finish setting it up by running bundle install in your project directory and then. rails generate rspec:install.
RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.
ActionDispatch::TestRequest
extends ActionDispatch::Request
that extends Rack::Request
.
The method is defined as follows
def referer @env['HTTP_REFERER'] end alias referrer referer
As far as I remember, you can access the environment variable in the RSpec test by using request.env
. It means, it should be possible to set something like
request.env['HTTP_REFERER'] = 'http://example.com'
Of course, it depends on the type of RSpec example group you are using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With