I am new to Ruby & Rails and basically come from Java background hence I apologize in advance for my limited knowledge of RoR.
Ruby version = 2.1
Rails version = 4.2
While working on an existing Rails 4 application I came across the following test written in one of the test files. This test is trying to test the login page of the application but I am puzzled by following questions:
- Is MiniTest used for just unit testing or integration testing or both?
- Is this test actually a MiniTest test or is it just importing existing default Ruby test framework in the helper file and not actually using any of the MiniTest features?
- Can MiniTest actually test DOM elements such as input text in user input boxes, do button clicks etc?
- Is it actually hitting the application by starting the server internally?
- Can MiniTest alone be used to test a Rails application end-to end by running in headless mode?
- Can MiniTest alone be used to test a Rails application end-to end by launching a browser through selenium? I know Capybara can do this.
- I guess this test is running against
localhost
. How can I make this test point to a different host suchwww.dev-server.com
?
login_test.rb
require 'integration_test_helper'
class LoginTest < ActionDispatch::IntegrationTest
setup do
@user = users(:admin)
end
test "login page is displayed on root path" do
delete '/signout'
get root_path
assert redirect?
assert_redirected_to '/signin'
follow_redirect!
assert_template :new
assert_template %r{\Adevise/sessions/new\Z}
assert_select "a[href=?]", users_path, count: 0
assert_select "input[id=?]", 'login-email', count: 1
assert_select "input[id=?]", 'login-password', count: 1
assert_select "button[id=?]", 'login', count: 1
end
end
integration_test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use! [Minitest::Reporters::JUnitReporter.new, Minitest::Reporters::SpecReporter.new(:color => true)]
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
....
end
`backticks`
to highlight words. They are for inline code only, not for adding emphasis. – meagar