I’ve thought to try to use Rspec. But I get a next problem with the assert_select.
1) UserController login page open login page contains all expected controls
Failure/Error: assert_select "form[action=?]", "/user/login" do MiniTest::Assertion:
Expected at least 1 element matching "form[action='/user/login']", found 0.
# (eval):2:in `assert'
# ./spec/controllers/user_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
This is my code snippet
describe UserController do
describe "login page open" do
it "login page contains all expected controls" do
get :login
assert_select "form[action=?]", "/user/login" do
assert_select "input[name=?]", "username"
assert_select "input[name=?]", "password"
assert_select "input[type=?]", "submit"
end
end
end
When I open a login page in a browser this page opens without problem.
By default, RSpec (at least in newer versions) prevents Rails from rendering views when you run controller specs specs. They want you to test your views in view specs, not controller specs. Since the views don’t render,
assert_selectalways fails.But for people who (like me) want to test the occasional snippet of a view in their controller specs, they provide a
render_viewsmethod. You have to call it in yourdescribeorcontextblock, though, not inside theitblock.