Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,390 --> 00:00:07,720
We can now add more tests to this file and our next focus is the date method that we use to format a
2
00:00:07,730 --> 00:00:08,570
date.
3
00:00:08,580 --> 00:00:11,150
So here we cannot a new group.
4
00:00:11,640 --> 00:00:19,410
And here we can name it date and we're gonna give it a body like this and then we could add a new test
5
00:00:19,410 --> 00:00:30,750
to check that the correct date is formatted so I cannot test with 20 19 0 8 twelve as a description
6
00:00:30,810 --> 00:00:36,950
to mean that the logos 2019 and then the method body as usual.
7
00:00:37,260 --> 00:00:43,350
And here I can right expect and then four month date.
8
00:00:43,680 --> 00:00:53,730
And here I need to pass up the date time with Twenty 19 eight twelve and the expected value in these
9
00:00:53,740 --> 00:00:59,750
cases twelve logos 29 things like this.
10
00:00:59,970 --> 00:01:08,820
And at this stage I could run this test and I can see that I get an error because the actual value that
11
00:01:08,820 --> 00:01:12,480
was return is different from my expected value.
12
00:01:12,660 --> 00:01:20,010
And in fact this expected value is only valid if I configured the default locale to G.B. and instead
13
00:01:20,190 --> 00:01:23,220
the test has run with the U.S. default lockout.
14
00:01:23,700 --> 00:01:26,400
So when we write tests they use date formatting.
15
00:01:26,490 --> 00:01:31,730
We need to be very careful because different systems might have different default locales.
16
00:01:31,920 --> 00:01:38,070
So we need a way of choosing what locale to use when we run tests that rely on data for mapping and
17
00:01:38,070 --> 00:01:38,580
to do that.
18
00:01:38,580 --> 00:01:47,490
I'm going to use a new method which is called set up and set up takes a closure that is executed before
19
00:01:47,610 --> 00:01:48,280
each test.
20
00:01:48,300 --> 00:01:49,870
In this group is run.
21
00:01:50,070 --> 00:01:56,060
And this makes it a very useful method for code that needs to be executed for each test.
22
00:01:56,070 --> 00:01:56,310
OK.
23
00:01:56,340 --> 00:02:02,790
So what I want to do next is to configure the default to look out for my test and I can do this by typing
24
00:02:02,850 --> 00:02:10,770
I and the L which I need to import from the I A.L. package and then I'm going to set the default locale
25
00:02:11,160 --> 00:02:23,970
to E and on the score G.B. and I also need to call initialize date for my thing and this is also a method
26
00:02:24,030 --> 00:02:33,240
that I need to import from here and here I can typing I and the l the default locale like this and this
27
00:02:33,300 --> 00:02:35,610
is a method that returns a future.
28
00:02:35,880 --> 00:02:41,610
So I need to type in I wait here and also sink in here.
29
00:02:42,330 --> 00:02:50,550
And now that I made this change I should remain this group to date with G.B. loco because all the tests
30
00:02:50,580 --> 00:02:53,650
that will run here will use that GBM locale.
31
00:02:53,820 --> 00:03:01,980
And now I can run the tests again and this time I got the success by the way I have said that we can
32
00:03:01,980 --> 00:03:06,750
use this setup method to execute some common code before each test is run.
33
00:03:07,170 --> 00:03:15,270
And this means that here we go that another test for example with a different date of the 16 of August
34
00:03:16,380 --> 00:03:18,680
and I can update this here.
35
00:03:19,230 --> 00:03:26,910
And in this case we could run this test again and this would also succeed because the correct lock out
36
00:03:26,970 --> 00:03:29,900
will be set up in the setup method.
37
00:03:29,970 --> 00:03:36,450
So if we wanted to ensure that our code works well with different locales we could copy paste this entire
38
00:03:36,450 --> 00:03:38,970
group and adjust all the values accordingly.
39
00:03:39,710 --> 00:03:40,010
OK.
40
00:03:40,050 --> 00:03:42,090
So let's continue on the next video.
4189
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.