minitest

Idiomatically mock OpenURI.open_uri with Minitest

匆匆过客 提交于 2019-12-01 11:48:44
I have code that invokes OpenURI.open_uri and I want to confirm the URI being used in the call (so a stub isn't going to work for me), but also intercept the call. I'm hoping not to have to abstract away the call to OpenURI.open_uri just for test purposes. What I've come up with seems verbose and overly complicated. under_test.rb require 'open-uri' class UnderTest def get_request(uri) open(uri).read end end test_under_test.rb require 'minitest/autorun' require './lib/under_test' class TestUnderTest < Mintest::Test def test_get_request @under_test = UnderTest.new mock_json = '{"json":[{"element

How do I mock an OmniAuth hash using Rails and minitest?

这一生的挚爱 提交于 2019-12-01 09:24:29
I'm using Rails 5 with minitest. I want to mock logging into my sessions controller, which relies on omniauth (I use Google and FB for login). I have this in my controller test, test/controllers/rates_controller_test.rb, class RatesControllerTest < ActionDispatch::IntegrationTest # Login the user def setup logged_in_user = users(:one) login_with_user(logged_in_user) end and then I try and set up login in my test helper, test/test_helper.rb, class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all def setup_omniauth_mock(user)

How do I mock an OmniAuth hash using Rails and minitest?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 05:40:50
问题 I'm using Rails 5 with minitest. I want to mock logging into my sessions controller, which relies on omniauth (I use Google and FB for login). I have this in my controller test, test/controllers/rates_controller_test.rb, class RatesControllerTest < ActionDispatch::IntegrationTest # Login the user def setup logged_in_user = users(:one) login_with_user(logged_in_user) end and then I try and set up login in my test helper, test/test_helper.rb, class ActiveSupport::TestCase # Setup all fixtures

Ruby minitest assert_output syntax

流过昼夜 提交于 2019-12-01 04:42:36
I am new to minitest and still new to ruby and really tired of trying to google this question without result. I would be really grateful for help: What is the exact syntax of assert_output in ruby minitest? All I find on github or elsewhere seems to use parentheses. Yet, I get an error message when I don't use a block with assert_output, which makes sense as the definition of this method contains a yield statement. But I cannot make it work, whatever I try. testclass.rb class TestClass def output puts 'hey' end end test_test.rb require 'minitest/spec' require 'minitest/autorun' require

Ruby minitest assert_output syntax

試著忘記壹切 提交于 2019-12-01 02:24:12
问题 I am new to minitest and still new to ruby and really tired of trying to google this question without result. I would be really grateful for help: What is the exact syntax of assert_output in ruby minitest? All I find on github or elsewhere seems to use parentheses. Yet, I get an error message when I don't use a block with assert_output, which makes sense as the definition of this method contains a yield statement. But I cannot make it work, whatever I try. testclass.rb class TestClass def

minitest, test::unit, and rails

…衆ロ難τιáo~ 提交于 2019-12-01 02:06:25
I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+". But ruby 1.9.3 seems to include both test::unit and minitest , is that true? In the default rails testing, as outlined in the Rails testing guide .... things like ActiveSupport::TestCase , ActionController::TestCase , are these using Test::Unit or Minitest ? In the rails guide, it shows examples with tests defined like this: test "should show post" do get :show, :id => @post.id assert_response :success end That syntax, test string , as opposed to defining methods with names like test_something -- isn't mentioned in the

minitest, test::unit, and rails

試著忘記壹切 提交于 2019-11-30 21:29:02
问题 I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+". But ruby 1.9.3 seems to include both test::unit and minitest, is that true? In the default rails testing, as outlined in the Rails testing guide.... things like ActiveSupport::TestCase , ActionController::TestCase , are these using Test::Unit or Minitest ? In the rails guide, it shows examples with tests defined like this: test "should show post" do get :show, :id => @post.id assert_response :success end That syntax,

How to sign_in for Devise to Test Controller with Minitest

梦想与她 提交于 2019-11-30 18:10:55
问题 I'm newbie to Rails Testing. After following some tutorial online, I could able to setup and run testing for Model. But when trying to test for Controller, Testing was failed as it is redirected to login page. I've tried every instruction I can find on web to sign in for devise and still couldn't able to sign in and move forward. Appreciate if someone could help and give me a direction to move forward. AwardedBidsControllerTest test_should_get_index FAIL (0.45s) MiniTest::Assertion: Expected

Creating a test suite using Ruby minitest

十年热恋 提交于 2019-11-30 17:58:06
问题 I'm moving my tests to the new ruby minitest library, and I am looking for the class that corresponds to the old Test::Unit::TestSuite class. All the examples I've found online show single test cases, but I've got: require 'minitest/unit/testsuite' require 'minitest/unit/ui/console/testrunner' require 'tests/fs_session_test' require 'tests/resource_test' require 'tests/rest_session_test' require 'tests/server_test' class AllTests def self.suite suite = Test::Unit::TestSuite.new suite <<

How to assert certain method is called with Ruby minitest framework?

天大地大妈咪最大 提交于 2019-11-30 14:31:03
问题 I want to test whether a function invokes other functions properly with minitest Ruby, but I cannot find a proper assert to test from the doc. The source code class SomeClass def invoke_function(name) name == "right" ? right () : wrong () end def right #... end def wrong #... end end The test code: describe SomeClass do it "should invoke right function" do # assert right() is called end it "should invoke other function" do # assert wrong() is called end end 回答1: With minitest you use expect