Summarized using AI

Secrets of Testing Rails 5 Apps

Prathamesh Sonpatki • June 23, 2016 • Singapore • Talk

The video titled "Secrets of Testing Rails 5 Apps" features a presentation by Prathamesh Sonpatki, who discusses significant improvements and changes in testing Rails 5 applications. The session aims to equip developers with essential knowledge on utilizing the new testing framework effectively.

Key points discussed in the video include:
- Introduction to Testing in Rails: Prathamesh opens with a light-hearted introduction and shifts focus to the importance of testing in development cycles, emphasizing the need for efficient feedback mechanisms when writing code.
- Changes in Test Running: Rails 5 introduces a new default test runner that enhances test execution with features missing in previous versions, such as running only failed tests, colored outputs, and the ability to specify test runs by line number. It provides a better user experience by streamlining commands like bin/rails test.
- Improvements in Writing Tests: The presentation covers a shift from using functional tests to integration tests as the default method for testing controllers.
- This change is due to integration tests simulating the actual request/response cycle, making them more reliable than the previous functional style tests, which bypassed this cycle.
- Functional tests are considered soft deprecated.
- Adapting to New Test Structures: With the switch to integration tests, there are several implications regarding how session variables and headers are handled, making it necessary to adapt existing tests to the new requirements.
- Enhanced API Testing: For APIs, new capabilities allow developers to easily write tests that handle JSON requests, allowing Rails to automatically manage content types and parameters.
- End-to-End Testing Focus: A significant takeaway from Prathamesh’s talk is the emphasis on end-to-end testing, encouraging developers to verify the overall behavior and output rather than diving into internal implementations.
- Resources for Further Learning: Prathamesh encourages viewers to explore additional resources like blogs and newsletters dedicated to Rails 5 for a deeper understanding of its new features.

In conclusion, testing in Rails 5 has been significantly improved, emphasizing ease of use and enhancing the testing experience for developers. The session highlights important shifts towards integration testing and better practices in the Rails ecosystem.

This informative talk is beneficial for both experienced Rails developers and those looking to understand the enhanced capabilities of Rails 5's testing framework.

Secrets of Testing Rails 5 Apps
Prathamesh Sonpatki • June 23, 2016 • Singapore • Talk

Speaker: Prathamesh Sonpatki, Director, BigBinary LLC

Testing Rails 5 apps has become better experience out of the box. Rails has also become smarter by introducing the test runner. Now we can't complain that about not able to run a single test or not getting coloured output. A lot of effort gone into making tests especially integration tests run faster. Come and join me as we will commence the journey to uncover the secrets of testing Rails 5 apps.

Speaker's Bio
Prathamesh is Director at BigBinary. He builds web apps using Rails and React.js!. He is interested in open source and contribute to many Ruby and Rails related projects. He likes Emacs operating system a lot and can be found constantly tweaking his .emacs.d

Event Page: http://www.reddotrubyconf.com/

Produced by Engineers.SG

Help us caption & translate this video!

http://amara.org/v/ONq1/

Red Dot Ruby Conference 2016

00:00:14.000 so uh my name is pramesh that's my Twitter handle uh last time I checked my Twitter followers at another conference
00:00:20.359 they were $9.99 so you can follow me but I'm not sure how much the count is right now so we'll see uh I'm director at Big
00:00:28.000 Miner we work on Rails uh B react react JS react native a lot of things so uh if
00:00:33.640 you want to talk about any of these uh catch me later uh yes and I she said I came uh from I I stay in Pune but I
00:00:41.600 didn't come from India I actually flew from San Francisco because I was there uh you should definitely come to Pune uh
00:00:48.199 we have good food good weather we also have a Rubicon in August so if you uh want to visit pun that's a good
00:00:55.399 excuse uh I'm part of rails issues team uh I have very big respons possibility as part of the issues team member I can
00:01:03.440 close issues if you open them I can close them uh I don't do it all the time
00:01:08.680 but sometimes I do close the issues so if I have close your issue I'm really sorry about it but I have to do it
00:01:15.240 sometimes I also have some warnings uh so the this talk is also a bit technical
00:01:21.119 non-technical that's fine but no durians and durian jokes are allowed during the
00:01:26.400 next two days at red. Ricon so all the durian jokes are are already over if you have those in your slides please remove
00:01:33.159 them uh I have another sad news for you uh and I'm just telling it up front in
00:01:39.399 at the start of my talk because uh I really don't want to disappoint you I cannot give you any stickers sorry I
00:01:46.880 have seen lot of speakers doing this like they say that okay I will give you stickers come and find me after my talk
00:01:52.680 but I'm really sorry I don't have them that doesn't mean I like I don't like them uh in fact uh this is my laptop and
00:01:59.399 I like stickers a lot so uh when I started seeing tweets about red. Rubicon
00:02:04.560 I was really excited because I saw that we were getting a lot of stickers uh I already got them in the morning but I
00:02:10.959 want more so I want these I also want these so if you have stickers come and
00:02:18.599 find me after my talk I'm wearing this kodri t-shirt and let's talk and give me your stickers
00:02:26.239 so I want them and I'm fine with anything I like t-shirts too so I like all fact okay on a serious note
00:02:34.560 uh I'm not going to talk about rspec I'm going to talk about uh the default rails uh test recipe that comes uh bundled
00:02:41.680 with rails uh rails 5 is very big release and there are a lot of changes related to how we should test our apps
00:02:48.680 too so I'm going to talk about some of those changes and I promise there are no
00:02:54.400 jokes after this everything is very serious uh we will be talking about some serious testing stuff and secrets and
00:03:01.159 everything so yeah let's start let me tell you the biggest secret about uh testing rails 5
00:03:06.560 apps and just delete your tests that's the biggest secret once you delete your
00:03:12.159 test you don't have to worry about anything the talk is over so uh thanks everyone if you have any questions uh I
00:03:18.440 can take them I'm just kidding don't worry uh I'm not going to stop like that I will be
00:03:24.440 speaking for next half an hour so now literally all jokes are over coming back to the actual content now so uh testing
00:03:32.159 is very important part of our daily life we we write test run test all the time
00:03:37.640 uh and rails 5 has some interesting changes for both running as well as uh writing
00:03:42.959 test when we run test uh we expect that we will get good feedback about uh the
00:03:48.560 tests uh because it's iterative process it's not like that we uh write code for
00:03:53.599 the first two days of the week and run tests on Wednesday after lunch at 1 p.m. uh we do it all the time so so uh the
00:04:01.840 output that we get from running the test is very important but sadly uh the default way
00:04:09.040 of running test in rails uh was not that great uh before rails 5 uh we run all
00:04:14.439 the tests using rake test we got some other rake task also to run specific test like controllers models and other
00:04:21.240 things but we miss out on a lot of things that are present in other libraries like we cannot rerun the
00:04:26.919 failed Snippets we cannot run test only by by specifying the line number of the test we cannot have options like fail
00:04:34.080 fast defer output in fact we even have to include a gem to get colored output I think that
00:04:39.880 should be the fundamental right of every tester right we should get colored output but that is also not possible by
00:04:45.440 default so and uh most importantly it's not like uh all of these things are not
00:04:51.280 possible a lot of gems are already providing these uh on top of mini test which is uh the library that uh rails
00:04:57.759 test uh Suite is built on so and mini test is uh very uh pluggable so you can
00:05:03.560 extend it using writing your own plugins and a lot of people are already doing it so maxius it provides all of these
00:05:10.479 features like uh failing test rerun and everything there is also M which uh we can use to run test only by line but
00:05:18.440 they were not present in rails so for rails 5 rails team decided that enough is enough let's make running test crate
00:05:24.520 again so DHS also said that he would like all of these features to to be Beed
00:05:30.080 inside rails itself rather than uh using individual gems so rails 5 will ship
00:05:35.360 with a proper test Runner uh instead of running our test through rake test we will now have to run them through this
00:05:41.759 test Runner and we can use it by uh running this bin rails test command and
00:05:47.120 it accepts proper argument so it is a proper executable which can accept uh like whatever options we want to pass
00:05:54.039 and it provides uh most of these missing features like rerunning Snippets uh running only fails test test uh getting
00:06:00.600 colored output and everything so we get uh these kind of messages when we run the test and we can reuse those uh lines
00:06:07.599 to rerun only fail fail tests and we can also provide some more
00:06:12.800 options like uh fail fast defer output back trace and most of these things which were not present earlier uh they
00:06:18.880 are Now supported uh this test Runner is based on Mini test uh because miniest 5
00:06:24.599 has a plugin architecture and rails now has its own plug-in and a custom reporter uh which provides all of these
00:06:31.960 options and obviously all of these features were already present in lot of libraries so it's it's like uh nothing
00:06:38.840 is new here uh it's just that it's now part of the uh default rail stack so there are a lot of uh Inspirations like
00:06:45.720 aspec Min test uh reporters and so on but the most important thing is uh Now
00:06:51.720 the default omakasa stack it supports uh these features by default so once you
00:06:57.039 create a new brand new rails 5 app or you UPG to rails 5 you have all of these by default in your uh test Suite you
00:07:03.599 don't have to do uh like you don't have to install any other gem it just works by
00:07:09.280 default so this was all about uh running the test now we will talk about uh writing test so there are some
00:07:15.599 significant changes in uh the way we write test in rails 5 uh so rails tests
00:07:21.599 have typically these three components like you write unit test for your models or uh your simple Ruby classes then you
00:07:27.800 have functional test uh which test the controllers and integration test are testing uh the scenarios like complete
00:07:34.000 uh scenarios of a particular feature there are not uh like there is no change related to unit test so that
00:07:40.840 stays as it is but functional and integration tests have changed a lot in
00:07:45.879 fact uh controller tests are the only ones that are most affected by rails 5 so they do deserve a special mention and
00:07:52.879 we will talk about them in detail so it's interesting actually uh
00:07:57.919 what we test in a controller test uh so they generally controller actions
00:08:03.159 handle incoming request uh in a rail app they do some processing with that request and returns uh Returns the
00:08:09.080 response uh or sometimes they redirect whatever but they return some response so when we want to test a controller uh
00:08:17.159 action we should test the response that comes out of that request so this is the typical
00:08:22.840 controller test case that we have in rails 4 uh here we are sending a request
00:08:27.879 post request for creating the Artic we are passing some prams uh we are checking whether the response got
00:08:33.560 redirected to a particular page but we are also testing some changes that that
00:08:39.279 are happening with database uh with this action so we are not really testing only
00:08:46.080 the response we are also testing uh the database changes which are not part of
00:08:51.279 the response so we are also changing some third party things which are not part of the response so we are actually testing the
00:08:58.160 current state we are not testing testing the response but we are testing the changes in the state that happened due
00:09:03.720 to that request and that state can be anything it can be uh controllers HTTP
00:09:09.399 respon uh response or it can be uh where we got redirected or it can be HTML
00:09:14.920 response or Json response it can be changes to the database also now one of the good things uh about
00:09:21.760 this uh controller test is they're very easy to write we can just write three four lines and we can test whether that
00:09:28.000 controller action works properly or not uh we can test response we can test database changes we have all the helpers
00:09:34.200 for them we can also test things like which template got rendered uh we can test uh which instance variables uh we
00:09:40.959 were using in that particular action it's very convenient uh to write and run uh controller tests but these controller
00:09:48.800 tests they actually lie they don't actually uh follow the same way that uh
00:09:54.399 rails follows when a typical request hits a rails app so they by pass that
00:09:59.880 typical uh request response cycle uh when uh these controller tests are run because when we run this kind of uh
00:10:07.839 functional style controller test there is no middleware stack that gets invoked uh when this test is run so it it just
00:10:14.680 directly hits that particular action and uh tries to see uh what is happening inside that action so even if we are uh
00:10:21.519 writing too many controller tests they're not actually following the uh request response CLE cycle that rails
00:10:28.279 actually uses uh when it uh serves requesting production so even if uh
00:10:33.399 controller tests are very easy to write uh they're not really testing your controller actions in true sense they
00:10:39.680 are just like unit testing uh your controller actions and that's where uh integration
00:10:45.760 tests come so that's the alternative to controller test uh in uh like functional style controller test in rails uh we can
00:10:52.680 write integration test because they don't bypass the uh middleware stack they follow the same structure that a
00:10:59.440 typical request follows uh when it hits uh the rail app and this is the simple uh uh
00:11:05.959 integration test uh from rails 4 so we can do almost the same things that we
00:11:11.279 can do with a functional style controller test we can uh send the request using the same uh request
00:11:17.079 helpers we can send params we can test whether uh what happened to the response whether it got redirected or uh anything
00:11:23.720 other than that we can also test uh the changes to the database similar to how we test them in functional style
00:11:30.800 tests so these integration tests they are almost same as controller test we can do the same things that we were able
00:11:37.279 to do in controller test the advantage is they're close to the real world so they simulate the same
00:11:43.639 process that happens when uh uh request actually comes and hits our app so it's
00:11:49.760 good to write uh integration test rather than writing functional style test but then why don't we write it why don't we
00:11:55.959 encourage uh writing uh integration test because the reason was before alss 5
00:12:01.480 they were really slow compared to the functional style test they were very slow and uh so that's why the
00:12:08.040 recommended way was to write uh functional style test when you want to uh test your uh controller
00:12:14.839 actions but uh there was a lot of work done uh during the development of rails
00:12:20.040 5 and uh now the integration tests are not that slow in fact they're as fast as
00:12:26.360 your functional style test in rails 5 so there there is no way uh so there is no need to actually have uh the old
00:12:32.959 functional t uh style test anymore we can just write uh integration test and they will work in the same
00:12:39.600 way and that's why uh integration controller tests are Now default in rails 5 so if you generate a new rails
00:12:46.680 app and uh generate a resource using scaffold you will get a test like this
00:12:51.920 instead of functional now it is using uh integration style tests so these will be generated by default now onwards uh in
00:12:58.839 real 5 and the old style functional controller test uh inheriting from uh
00:13:05.240 action controller test case they're not gone completely but they are soft deprecated so that code is still present
00:13:11.440 in the rails repository and you will be still able to use those kind of test in 5.0 but uh rails by default will not
00:13:19.399 generate them uh rails will generate integration tests so they will still continue to
00:13:24.920 work if you have your older test uh and you're upgrading an older app from 4 to 5 and if you have such test they will
00:13:31.480 still continue to work uh this code base related to action controller test case uh might be removed
00:13:38.079 in future versions of rails so uh it can be uh put into a separate Gem and we
00:13:43.399 will have to include that gem if we still have those tests in uh some other major versions of
00:13:50.360 rails so even if I said that uh integration tests are almost same you
00:13:55.519 can do same thing that you are able to do in controller test there are some implications which we need to talk about
00:14:01.920 uh because things are not exactly as same as functional style test uh with integration tests so with rails 4 uh it
00:14:10.199 is possible to access session directly in our setup or uh in any uh any other
00:14:15.440 test also so we can do something like this we can access the session set some value and then uh we we can uh access
00:14:21.639 that in our test basically we can assert against that what we are really doing here is we are sort of bypassing hitting
00:14:27.839 the actual Endo which which hits that this session value and we are actually testing the Second Step uh after hitting
00:14:35.079 uh after uh assigning the session but this will not work in rails
00:14:40.199 5 so uh you cannot uh use uh like you cannot use session in the same way that
00:14:45.560 uh you are allowed to use in rails 4 so if you try to do this uh same with
00:14:51.440 rails 5 we will get an error like undefined meod session for nil nil nil
00:14:56.680 class because uh in 5 we have to actually send the post request for that
00:15:02.279 particular URL which will set the session in in the controller code so instead of us setting the session uh
00:15:08.279 directly through test we have to set we have to introduce another level which will directly hit that URL set the
00:15:14.839 session and then we can test what we wanted to test we can also like extract
00:15:20.160 this is a very common pattern and we will most probably need it for all of our tests so we can also extract it uh
00:15:25.600 into a helper method so if you using device uh you might might be used to writing like sign in as and then the
00:15:31.920 username that actually sets the session internally directly uh in the controller test but that will not work uh in ra SP
00:15:38.800 so if you are used to writing feature test you might be logging in uh for the every request like uh in setup Block
00:15:46.240 login for every request and then test what you wanted to test so we have to follow the same way now uh for
00:15:52.160 integration test in rails 5 same is uh same case with things like
00:15:57.360 headers also so earlier it was possible to directly set headers on request and other stuff uh that is also not possible
00:16:04.160 now uh you have to send those uh headers separately as part of parts of the argument uh to that request so because
00:16:11.959 of this change of uh switching to integration test as default our functional style controller tests are no
00:16:18.040 longer functional style controller test so all the rules of uh writing a integration test now applied to uh
00:16:24.920 writing a controller test and these integration tests are like more blackbox style tests rather
00:16:31.920 than uh than uh our functional test so uh we are not actually allowed or recommended to uh test the internals of
00:16:39.199 our functional style test we have to test what comes out of them so it is like more blackbox testing than what we
00:16:45.920 had before and this brings us to the interesting question like what now we
00:16:52.519 cannot test in a controller test that uh it has changed the integration test what we cannot do that we were allowed to do
00:16:59.160 before so the recommended way is uh as it is more blackbox testing don't go
00:17:05.120 inside the controller and try to test more and more controller internals now what are the controller internals let's
00:17:10.760 see uh one of the example so uh we can have something like
00:17:16.240 this we we have some instance variable in our uh controll actions and in rails 4 it was allowed uh it was allowed that
00:17:23.679 you can test which uh instance variable was assigned using this assigned helper you can test what template got rendered
00:17:30.640 so this all was possible uh in rails for but is it really testing the thing that
00:17:35.840 we wanted to test uh we are just verifying that uh this instance variable was assigned but we are not testing the
00:17:41.880 value we are testing this template got rendered but not actually testing what actually got rendered from that template
00:17:48.120 so we are just scratching the surface we are not actually testing the things uh that the controller is
00:17:54.200 doing so the same test can be ritten uh in a rails 5 Style integration test and
00:18:00.600 uh we we here we we are actually asserting against the uh actual template here like what actually got generated uh
00:18:07.480 through this uh HTTP request so we are select like we are checking the Dom and seeing like this particular element uh
00:18:14.600 got rendered uh and then this can match our database values so if if I have a
00:18:19.679 repo with this particular name then I can test uh my dom that okay this response got generated and this that
00:18:26.280 response has uh this particular test now you must be worried like why I'm doing
00:18:31.960 uh these kind of things I'm coupling my uh test with uh the generated HTML or
00:18:37.240 generated Json so actually that's what uh the integration tests are trying to
00:18:43.039 uh recommend they're trying to recommend that test the response that got generated from the request rather than
00:18:48.200 testing this uh hypothetical things like uh say like insance variables or
00:18:53.240 template directly test the response that got generated uh from the request so uh this G uh rails Dom
00:19:00.840 testing gem it provides a lot of helpers for asserting facts against the generated HTML and uh I just show an
00:19:08.480 example of assert select but there are a lot of other things like CSS select and you can have your custom accounts for
00:19:14.640 how many elements you want and stuff like that so uh this gem can be a useful thing for writing controller tests in
00:19:20.880 rails 5 so what we are actually trying to do is we are not really testing the
00:19:26.240 controller particular controller action in isolation we are testing the controller and view
00:19:31.400 together so it's like you're test treating the controller and view interface as the same thing so we are
00:19:38.120 more and more focusing on end to end testing what is getting generated from that particular request and we are
00:19:43.320 asserting against uh what got out of uh the response and all of these things like
00:19:50.080 assigns assert template all of these helpers they were actually testing the view interface like what got passed from
00:19:55.400 my controller to my view but now we are treating it as a blackbox so everything
00:20:00.440 is uh as a black controller and view are together we are not allowed to or recommended to go inside and test what
00:20:06.440 is happening inside and we are just uh testing what is coming outside of that blackbox so we are no longer testing the
00:20:13.840 controller view interface that we were testing in rails 4 so the controller view interface is
00:20:19.919 just like an implementation detail rails has some way of passing data from controllers to views we don't have to
00:20:25.799 actually test how it is passing or what it is passing we just uh we just test uh what comes out of it and that's why uh
00:20:34.080 these helpers Asser template assigns they're all deprecated in rails F so if you are using these helpers you will get
00:20:39.919 a warning uh in rails F you cannot run U those stest
00:20:45.200 directly but another question why were why we were doing it in the first place why we were testing uh such things like
00:20:52.440 uh instance variables or which template got rendered why we testing the controller view interface because
00:20:59.039 sometimes it's useful to test that controller view interface in isolation let's say uh you're building a rails
00:21:05.000 engine and you have a separate app which is consuming that engine so in that case you your controller is coming from the
00:21:11.799 engine but views are present in your rails app so in that case it's uh important to actually see that your
00:21:17.679 controller is specifying a particular contract and it is providing certain instance variables to your views so in
00:21:23.840 that case it can make sense to actually test the controller view interface
00:21:29.039 uh so if you're using device in that case the controllers are present in device but your views are present in
00:21:34.679 your rail app so we know that okay these instance variables are available from our device controllers which we can use
00:21:40.720 in our views so in such cases it's important to actually test uh this interface in isolation too that's why uh
00:21:48.480 rails has not completely removed it so it's present in a gem uh rails controller testing Gem and if you're
00:21:54.279 upgrading to rails 5 from rails 4 uh and if you have such tests you can include
00:21:59.400 this Gem and thanks to goang he wrote this gem so uh you can include this Gem
00:22:06.480 and you will get those helpers uh in your rails 5 app so let's talk about uh the HTTP
00:22:13.440 request methods that we use for uh testing our controller actions like get post patch uh Delete and
00:22:20.400 whatever so we use these helpers uh like post and we pass the parameters like I
00:22:25.880 want to create a a product with name name FIFA so I'm passing the uh parameters as a hash and if you see we
00:22:33.640 are not specifying anywhere that that that product name FIFA is to be considered as params we are just
00:22:40.200 specifying the hash directly so we are using positional arguments the first argument that we pass to the HTTP
00:22:46.080 request method is uh the uh is the params ra knows it internally but it's
00:22:52.640 not the only argument that we can pass we can pass optional hash of session variables we can pass optional hash of
00:22:59.440 flash values and if you notice everything is optional so all the three arguments are optional so it it's okay
00:23:07.520 when you start with writing like sending just params but it gets tricky when you start writing like you don't want params
00:23:13.880 but you want flash you want flash but you don't want session variables so it gets really confusing like this so here
00:23:20.279 in this case I don't want name uh sorry I don't want params but I want Flash and session variables I don't want params
00:23:27.240 and session variables I want only flash so it gets very tricky and confusing what I'm really trying to do so no idea
00:23:34.720 what I'm trying to do okay it worked so in rails 5 uh we have a better
00:23:43.000 solution now we no longer have those uh positional arguments because rails 5 depends by default on Ruby 2.2.2 plus so
00:23:51.440 we can use keyword arguments for uh such uh uh helper methods and uh rails is
00:23:57.520 taking advantage of keyword arguments and now if we try to pass the params directly as params without specifying
00:24:03.840 anything we will get a deprecation warning that you have to pass them through uh keyword arguments so we can
00:24:09.640 now specify uh like these are my params these are my session varibles these are my flash messages using keyword argument
00:24:15.720 so it's become a bit better if your test is uh using action controller test case
00:24:20.760 then we have access to params flash session and Ajax request or not and if you're using integration test then we
00:24:27.440 have access to params environment headers and Etc so if you're using like
00:24:34.000 if you generate uh new rails tests in rails 5 uh you cannot set session and other things because uh action dispatch
00:24:41.080 integration test uh don't allow those keyword arguments this also has some
00:24:46.840 implications nothing is free so if you have something like this in rails 4 where you are passing the uh params as
00:24:53.919 the first argument and the key of the param is session so this used to work in rails 5 uh rails 4 it used to treat uh
00:25:01.240 this uh params key with session but in rails 5 this session is interpreted as
00:25:07.240 session not perams because session is the keyword argument which uh which has some meaning in rails 5 so if you you're
00:25:14.919 uh if you have something like this Edge case it may not work correctly in rails 5 so that's one thing to note about uh
00:25:22.360 these uh request methods let's talk about uh testing API requests so rails 5
00:25:29.480 you can generate Now API only apps uh in API only apps we have Json or XML
00:25:35.120 request we don't have HTML requests so we have to have some better way of uh testing um uh those
00:25:42.200 requests so by default uh when we write a controller test or integration test the request is treated as a HTML request
00:25:50.360 if you don't specify what we want to actually do so in case of rails 4 if you
00:25:56.080 have to specify it as a Json thing uh we we have to specify a lot of things like we have to specify the format we have to
00:26:01.919 specify the param suggestion we have to also specify the content type as so too
00:26:07.279 many times we have to specify what we want to do uh instead of that if there was some way that rails can internally
00:26:13.919 figure out that this is Json request so I have to pass the param Json I have to set these proper headers it will be good
00:26:20.480 for us so we don't have to specify a lot of things and that's what rails fight does so we just have to specify the
00:26:26.240 request as ad Json and in internally it will figure out that okay I have to set these headers I have to set my I have to
00:26:32.720 send my params as Json params so we don't have to specify everything
00:26:37.840 manually it will just work out of the box and one more good thing about this is uh if you're testing the response
00:26:44.360 that comes out of your Json endpoint uh you have to actually uh like convert your body to Json before testing it but
00:26:51.440 when you specify the encoder as Json uh it will figure out of uh converting the body to Json format also so uh one more
00:26:59.159 helper method can be removed from your uh test cases so yeah it figures out the content
00:27:06.039 type based on what you uh want and then it will use the pass body like we can use the pass body method to uh test uh
00:27:13.360 to write assertions so this was all about uh like controller functional integration test
00:27:20.120 but there are some other changes too so uh there is a now active job a sync adapter for our test so by default
00:27:27.240 active active job had two adapters inline and a sync but only inline was default for uh writing active job test
00:27:35.080 so if you're using Sid kick in production then when you're writing test and writing test for your active job uh
00:27:42.039 classes they were actually using the inline adapter so even if you're using uh like if by default like by any chance
00:27:48.760 if you're dependent on any asynchronous behavior in production in development you are doing things in synchronous
00:27:54.240 fashion so now rails 5 will have a uh a sync adapter which will be default for a
00:27:59.919 test mode so uh it will be uh as close to uh your production environment as
00:28:06.279 possible so it's like a better default option to have because we will not run into uh random issues which happen only
00:28:13.000 in production so rails can speed up our test uh more by running test in parallel
00:28:20.360 like it can use your CPUs it can use different processes to run test faster but for that we also have to make sure
00:28:27.640 that if you if we run our test in random order they will not fail randomly sometimes that happens like your one
00:28:33.200 test is dependent on your second test the order matters so rails 5 will also have this configuration option where the
00:28:40.279 test will run in random order by default so even if the parallel thing uh like
00:28:45.919 speeding up test using parallel test has not happened yet it's sort of a good step towards that goal that now we have
00:28:52.640 our test running in random order so we can fix issues uh which are dependent on uh running test in a particular order
00:28:59.919 and we can we may fix some of the like some of the bugs also in our
00:29:05.679 apps so uh testing in rails 5 is better experience a bit smarter experience with
00:29:11.399 the introduction of test Runner because now we can run tests more effectively than we used to do uh there are a lot of
00:29:18.519 things that have changed related to controller testing also but I think the biggest uh takeaway is that we are
00:29:24.240 moving towards writing more end to end testing and we are not writing uh many uh like we are not writing the
00:29:31.159 old style functional test so we we are more focusing on writing end to end
00:29:37.679 tests uh there is much more in rails 5 than this we we just covered uh the changes related to testing today but if
00:29:44.600 you want to know uh more about rails 5 we have a Block series on Rails 5 so we have around more than 50 block posts on
00:29:52.159 various features in rails 5 so I would highly recommend uh checking that uh there is also a newsletter this week in
00:29:58.640 rails started by Godfrey who is uh the rails score team member so if you subscribe to this newsletter you will
00:30:04.200 get a like weekly scoop of things of what happened in rails in that particular week so I will high highly
00:30:10.799 recommend this too if you are interested in knowing what is happening in rails uh in each week and that's all I have thank
00:30:26.679 you thank you thank you wait is this work okay thank you PR
00:30:35.840 MH for your really really cool talk on tests um any questions for
00:30:43.480 him we can accept one question before
00:30:48.840 lunch okay I guess all of you are hungry um anyway uh take note of his
00:30:54.320 Twitter handle if you um want to contact him he's also here in Singapore for um
00:31:00.799 quite a few more days so uh say hi thank you very much thank
Explore all talks recorded at Red Dot Ruby Conference 2016
+17