Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Last active January 9, 2017 23:32
Show Gist options
  • Save davidcornu/91f248ad66dd8df2dc41b22728f9a3fd to your computer and use it in GitHub Desktop.
Save davidcornu/91f248ad66dd8df2dc41b22728f9a3fd to your computer and use it in GitHub Desktop.
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails", branch: "5-0-stable"
gem "pry-byebug"
end
require "action_controller/railtie"
class TestApp < Rails::Application
config.root = File.dirname(__FILE__)
config.session_store :cookie_store, key: "cookie_store_key"
secrets.secret_token = "secret_token"
secrets.secret_key_base = "secret_key_base"
config.logger = Logger.new($stdout)
Rails.logger = config.logger
routes.draw do
resources :users, only: [:index]
end
end
class UsersController < ActionController::Base
def index
unless cookies[:name].present?
cookies[:name] = "Alice"
end
render plain: "Home"
end
end
require "minitest/autorun"
require "rack/test"
class UsersControllerTest < ActionController::TestCase
setup do
@controller = UsersController.new
@routes = Rails.application.routes
end
test '#index sets a cookie if it is not already present' do
get :index
assert_response :ok
assert_equal "Alice", cookies[:name]
cookies[:name] = "Bob"
get :index
assert_response :ok
assert_equal "Bob", cookies[:name]
end
end
Fetching git://github.com/rails/rails.git
Fetching gem metadata from https://rubygems.org/........
Fetching version metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 12.0.0
Using concurrent-ruby 1.0.4
Using i18n 0.7.0
Using minitest 5.10.1
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 2.0.1
Using nio4r 2.0.0
Using websocket-extensions 0.1.2
Using mime-types-data 3.2016.0521
Using arel 7.1.4
Using bundler 1.13.6
Using byebug 9.0.6
Using coderay 1.1.1
Using method_source 0.8.2
Using slop 3.6.0
Using thor 0.19.4
Using tzinfo 1.2.2
Using nokogiri 1.7.0.1
Using rack-test 0.6.3
Using sprockets 3.7.1
Using websocket-driver 0.6.4
Using mime-types 3.1
Using pry 0.10.4
Using activesupport 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using loofah 2.0.3
Using mail 2.6.4
Using pry-byebug 3.4.2
Using rails-dom-testing 2.0.2
Using globalid 0.3.7
Using activemodel 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using rails-html-sanitizer 1.0.3
Using activejob 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using activerecord 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using actionview 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using actionpack 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using actioncable 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using actionmailer 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using railties 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Using sprockets-rails 3.2.0
Using rails 5.0.1 from git://github.com/rails/rails.git (at 5-0-stable@d5e3fd7)
Run options: --seed 56214
# Running:
I, [2017-01-09T18:32:00.743065 #86520] INFO -- : ---------------------------------------------------------------------------
I, [2017-01-09T18:32:00.743127 #86520] INFO -- : UsersControllerTest: test_#index_sets_a_cookie_if_it_is_not_already_present
I, [2017-01-09T18:32:00.743139 #86520] INFO -- : ---------------------------------------------------------------------------
F
Finished in 0.112710s, 8.8723 runs/s, 35.4893 assertions/s.
1) Failure:
UsersControllerTest#test_#index_sets_a_cookie_if_it_is_not_already_present [test.rb:57]:
Expected: "Bob"
Actual: "Alice"
1 runs, 4 assertions, 1 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment