You’ve set up RSpec for your new Rails project but… what about data? You can’t write many tests without having some sample data and therefore we need a way to deliver them! However, what would be the optimal solution? Should we type them by hand? Should we generate them somehow?

In this video you are going to learn about two ways of managing sample data: fixtures and factories. Apart from that, you’ll learn about annotate gem to add annotations for models and specs, and faker to easily generate fake data. Testing continues!

You can find code samples for this screencast on GitHub:

Loading the player…

jwplayer(“video-5897”).setup({
image: “https://d3rj1gznkm47xj.cloudfront.net/d04ce9ea-5f42-4c04-899d-056f892dad11.png”,
sources: [
{
file: “https://d3rj1gznkm47xj.cloudfront.net/f3f519e8045d3af496ef3521b6e2692e.mp4”,
label: “SD”
},
{
file: “https://d3rj1gznkm47xj.cloudfront.net/09f6df31b8a844d42ac80cbfa5cb1c7b.mp4”,
label: “HD”
},
],
tracks: [
{
file: “http://djdvv9xnh2mt5.cloudfront.net/5cde0af0-cf6a-4621-8e8b-de2b2bf2707c.srt”,
“default”: true
}
],
aspectratio: “16:9”,
width: “100%”,
height: “480px”,
fallback: true,
primary: “flash”,
streaming: false,
analytics: {
enabled: false,
cookies: false
},
captions: {
back: false,
fontsize: 12
},
advertising: {
client: “googima”,
schedule: {
“myAds”: {
“offset”: “pre”,
“tag”: “https://pubads.g.doubleclick.net/gampad/ads?sz=855x483u0026iu=/7448792/Videou0026cust_params=[post_id]%3Dstaging%26channel%3D[channel]u0026impl=su0026gdfp_req=1u0026env=vpu0026output=xml_vast2u0026unviewed_position_start=1u0026url=[url]/u0026description_url=[description_url]u0026correlator=[timestamp]”
}
}
}
});

Continue reading %Watch: Managing Sample Data with Fixtures and Factories%

Source: SitePoint