-
Notifications
You must be signed in to change notification settings - Fork 252
Adds ability to use device model and OS on image names #121
Conversation
NSString *model = [device.model stringByReplacingOccurrencesOfString:@" " withString:@"_"]; | ||
NSString *os = [device.systemVersion stringByReplacingOccurrencesOfString:@"." withString:@"_"]; | ||
|
||
fileName = [NSString stringWithFormat:@"%@_%@%@", fileName, model, os]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: We don't tend to align on the =
; I'd prefer if we stuck to a single space before and after the =
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it; let me remove that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, were you to separate this logic out into a separate function or object, whose only responsibility was to format the strings returned by -[UIDevice model]
and -[UIDevice syetemVersion]
, this code would be a little cleaner. It'd also be easier to test.
Speaking of which, how about some tests for this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I added a test case for this but it looks like I only added it to ashfurrow/Nimble-Snapshots#32
I'll separate the formatting logic elsewhere (more so because I wanted to actually have iPhone 5s
as the model and that would required an extension on UIDevice
) and will correctly show the desired model and will also add a test for it tomorrow morning
Awesome stuff, thanks! 👍 I had a few suggestions on the implementation. @nscoding or @adamjernst may have opinions on whether this feature should be added in the first place. |
I don't have a problem merging this in, if everyone is onboard. It's a cool feature that we can include. You can achieve the same by providing your own specific suffixes function but this is clearly easier and you don't need another marco. So:
|
Finally got some time and made some changes. Slightly changed the approach because the simulator was not able to detect the «simulated device» and instead would store all images as To this I was suggested to instead save them by screen bounds since different models won't necessarily affect the output of a test but rather the
TODO:
|
Ok @nscoding, @modocache I made the suggested changes, including a small test and added an entry to the Feel free to review again whenever you guys have the time 🙇 Thanks |
@@ -103,6 +103,11 @@ | |||
@property (readwrite, nonatomic, assign) BOOL recordMode; | |||
|
|||
/** | |||
Specifies if the snapshot should have the name of the device model and OS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write what is the default value.
@esttorhe Nice! What if I run test on other iPhone, eg. iPhone 5s. Will test compare file above anyway, or after set |
@Grubas7 if That's a desired behavior because I would like to know that on an |
@esttorhe Just asking ;) Default value is |
hehehe yeah; default value is |
if (self.isDeviceAgnostic) { | ||
fileName = FBDeviceAgnosticNormalizedFileName(fileName); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Awesome stuff @esttorhe, can you squash the commits before I merge? |
Sure; give me a sec |
Add «device agnostic» support for the snapshots. Renamed property. Instead of `recordModelAndOSInName` now using `deviceAgnostic` and `isDeviceAgnostic` for better readability. Suggested changes from the PR - Extracted the «path normalizer» to FBSnapshotTestCasePlatform - Removed alignment of `=`s - Added property to the test case. - Add tests Added test for the device agnostic method. Added `isDeviceAgnostic` entry to the README Housekeeping 🏠 - Fixed internal documentation to state default values - Changed `UIScreen` in favor of `UIWindow` as per 's recommendations.
@nscoding squashed into 1 single commit now |
Adds ability to use device model and OS on image names
🎉 |
@nscoding sorry to bother; any chance to cut a new |
I want to do it with #119 merged in but we are almost there |
Sure; no rush 😄 Just wondering 👍 |
@esttorhe this is awesome! 👍 Out of curiosity, do you script the running of your tests over an array of devices so you don't manually run them in Xcode? |
@diachini I'm currently using ashfurrow/Nimble-Snapshots#32; there's a flag inside that framework that switches the check for images for a «record images» instead. Using Granted is not the most beautiful/easiest way but I had to set it real quick; I'm thinking in revisiting this later to add an easier way to achieve it. |
We like to actually record snapshots on multiple devices and multiple
OS
s (using bots for example is easier to automate testing oniPad
/iPhone
and a combination of differentOS
s).Instead of having to manually pass the data to each test I added a new property:
recordModelAndOSInName
which is used to check if those elements should be added to the recorded/retrieved image later on the comparison; resulting on an image name like the following:Probably the names of the functions & properties could use some imagination but the functionality is there.