minitest

How can I test multistep forms with Capybara & Minitest?

て烟熏妆下的殇ゞ 提交于 2019-12-13 02:24:43
问题 I have a single page Sinatra app that has a multistep form/wizard interface. If I want to test the form with Capybara, will need to repeat all the steps for each test? I'm hoping to avoid something like this: it "visits the home page" do vist "/" page.should have_content('foo') end it "clicks the first button" do vist "/" page.should have_content('foo') button_click("Next") end it "clicks the second button" do vist "/" page.should have_content('foo') button_click("Next") page.should_have

How to make rake test not use the default minitest?

主宰稳场 提交于 2019-12-12 17:03:42
问题 I am following along the Make your own Gem Guide from RubyGems. Executing the rake test instructions fails as follows: > rake test ~/.rbenv/versions/2.1.2/lib/ruby/2.1.0/minitest/unit.rb:26:in `const_missing': uninitialized constant MiniTest::Test (NameError) <rest of output truncated> I figured that it is because the minitest version being used is 4.7.5 and not 5.6.0 (or any of the 5.0.0 series that is needed to have MiniTest::Test be valid). So I installed minitest 5.6.0 and now I have both

How can I stub rand in minitest?

一笑奈何 提交于 2019-12-12 12:12:29
问题 I've tried Random.stub :rand, 1 do ... end and Kernel.stub :rand, 1 do ... end and Class.stub :rand, 1 do ... end (because when I run self.class where I run rand(2) I get Class ). I've also tried replacing rand(2) with Random.rand(2) but it doesn't help. So how do I stub out rand? 回答1: rand is part of the Kernel module that is mixed into every class. To stub it, you need to call stub on the object where rand is being called. It's probably easiest to see in an example. In the following code,

How to Pass an authorization-token-header in an integration-test?

寵の児 提交于 2019-12-12 10:44:59
问题 A related question implies that I can test a request with token authentication, in my intergration tests, as follows: get "/v1/sites", nil, :authorization => "foo" assert_response :success For some reason, the headers don't get to my application: get "/v1/sites", nil, :authorization => "foo" assert_match response.headers, /foo/ Expected {"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-UA-Compatible"=>"chrome=1", "WWW-Authenticate"=

Error “cannot load such file — 2.0/Console_ext” running unit tests in RubyMine

被刻印的时光 ゝ 提交于 2019-12-12 09:46:41
问题 I'm trying to get started running unit tests for a sample ruby on rails application however RubyMine is printing out the following error whenever I try and run unit tests I've also gotten the same error when running bundle install since I added gem "win32console", '1.3.0' to my Gemfile. Here is the error in text form Exception message: cannot load such file -- 2.0/Console_ext ["D:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/win32console-1.3.0-x86-mingw32/lib/Win32/Console.rb:12:in

How do you perform javascript tests with Minitest, Capybara, Selenium?

女生的网名这么多〃 提交于 2019-12-12 07:59:51
问题 There are a lot of examples on how to perform javascript tests with Capybara/Selenium/ Rspec in which you can write a test like so: it "does something", :js => true do ... end However with minitest you can't pass a second parameter to instruct selenium to perform the test. Does anyone have any ideas on how this can be done? 回答1: What :js flag is doing is very simple. It switches the current driver from default (rack-test) to another one that supports javascript execution (selenium, webkit).

Count; find User with id= Minitest

家住魔仙堡 提交于 2019-12-12 04:36:59
问题 I am following Michael Hartl's Ruby on Rails tutorial and I am not sure why I am getting this Error when according to the tutorial everything should pass: 1) Error: UsersControllerTest#test_should_get_show: ActiveRecord::RecordNotFound: Couldn't find User with 'id'= app/controllers/users_controller.rb:7:in `show' test/controllers/users_controller_test.rb:10:in `block in <class:UsersControllerTest>' My minitest: require 'test_helper' class UsersSignupTest < ActionDispatch::IntegrationTest #

Rails Pundit mini test assert_response Pundit::NotAuthorizedError

妖精的绣舞 提交于 2019-12-12 04:28:08
问题 I am using Rails 5 API, Pundit and all is going well. I am trying to test this specific case where if you're not the resource owner, you should not be able to view that user's info. So I got a few user fixture sample data, Sarah and Jim are two of them. I got this test case here: test "user show - cannot show other user's info" do get user_path(@sarah), headers: user_authenticated_header(@jim) assert_raises(Pundit::NotAuthorizedError) end I ran my test, all the other ones passed, except this

Setting current_user in system tests

社会主义新天地 提交于 2019-12-11 17:02:45
问题 I'm using system tests to verify that the following flow works as expected for a user: Sign up in a form Get signed in Visit account page Update account information However, I'm getting an error after user creation: Puma caught this error: Couldn't find User with 'id'=16 (ActiveRecord::RecordNotFound) /Me/MyComputer/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activerecord-5.1.4/lib/active_record/core.rb:189:in `find' /Me/MyComputer/Documents/my_app/app/controllers/application_controller.rb

How can I write a shortcut for signing a user in in my integration tests?

百般思念 提交于 2019-12-11 14:49:48
问题 Motivated by the discussion in this question, I want to write a log-in method for my integration tests. In my test_helper.rb I even found such a method, but it is defined inside a ActiveSupport::TestCase class, and my test inherits from ActionDispatch::IntegrationTest . So I copied the method and put it (inside test_helper.rb ) into the ActionDispatch::IntegrationTest class. But it doesn't work and my tests fail with this message: Capybara::ExpectationNotMet: expected "data:," to include