SlideShare una empresa de Scribd logo
1 de 35
Fixture replacement plugins Jakub Suder Lunar Logic Polska
Why fixtures aren't enough „Rails test fixtures are evil and a plague upon developers.”   http://b.logi.cx/2007/11/26/object-daddy „If you are still using fixtures, there is no hope for you. Become a forest ranger.” http://blog.adsdevshop.com/2009/02/23/factories-for-test-objects-use-them/
Why fixtures aren't enough ,[object Object]
no one remembers the „story” it "should be possible to delete a folder only in a group that you're a member of" do folder = folders(:ruby) folder.should be_deletable_by(users(:joe)) folder.should be_deletable_by(users(:joan)) folder.should_not be_deletable_by(users(:bill)) end
Why fixtures aren't enough ,[object Object]
fixtures can be invalid
some things are much more difficult than they should be
not DRY
slow?
Why fixtures aren't enough ,[object Object],class ScheduleEntryFfsBillingTest < Test::Unit::TestCase fixtures :parties, :locations, :cost_centers, :service_places, :activities, :logins, :tuple_domains, :tuples, :client_payer_relations, :credentials, :gl_mappings, :panels, :panel_members, :panel_payers, :fee_matrices, :fl_matrices, :payer_fee_matrices, :pfl_matrices, :pdcrf_matrices, :care_domains, :care_domains_objectives, :client_domains, :allowed_cost_centers, :authorizations, :positions, :accountabilities, :commissioners, :responsibles, :accountability_positions, :chart_entries, :observations, :gl_mappings, :gl_mapping_types, :tags, :taggings, :form_sets, :form_items, :choices def test_validate_ffs_billing count = ScheduleEntry.ffs_ready_to_bill.size assert_difference BillableItem, :count, 98 do entries = ScheduleEntry.validate_ffs_billing assert entries end assert_equal count-130, ScheduleEntry.ffs_ready_to_bill.size end end ( http://b.logi.cx/2007/11/26/object-daddy )
Solutions ,[object Object],def create_event(options = {}) Event.create({:name => 'Event 1', :location => 'Krakow', :date => Date.today}).merge(options) end ,[object Object]
doesn't handle uniqueness
Solutions ,[object Object]
Object Daddy
Factory Girl
Machinist
DM-Sweatshop
FixtureReplacement ,[object Object]
FixtureReplacement (db/example_data.rb) module FixtureReplacement attributes_for :user do |u| password = String.random u.value  = &quot;a value&quot;, u.other  = &quot;other value&quot;, u.another  = String.random,  # random string 10 characters long u.one_more  = String.random(15), # 15 characters long u.password  = password, u.password_confirmation  = password, u.associated_object = default_bar  # expects attributes_for :bar end end
FixtureReplacement ,[object Object]
new_user -> User.new
create_user -> User.create!
default_user -> for use inside model_attributes definitions
new_user(:thing => &quot;overridden&quot;)
john = create_user(:username => &quot;john&quot;)
circumvents attr_protected by assigning manually
Object Daddy ,[object Object]
Object Daddy class User < ActiveRecord::Base generator_for :email, :start => 'test@domain.com' do |prev| user, domain = prev.split('@') user.succ + '@' + domain end generator_for :username, :method => :next_user generator_for :name, :start => 'Joe' generator_for(:start_time) { Time.now } generator_for :name, 'Joe' generator_for :age => 25 def self.next_user @last_username ||= 'testuser' @last_username.succ end end
Object Daddy class User < ActiveRecord::Base generator_for :ssn, :class => SSNGenerator  end class SSNGenerator def self.next @last ||= '000-00-0000' @last = (&quot;%09d&quot; % (@last.gsub('-', '').to_i + 1)).sub(/^({3})({2})({4})$/, '--') end end
Object Daddy it &quot;should have a comment for every forum the user posts to&quot; do @user = User.generate @post = Post.generate @post.comments << Comment.generate(:title => 'first post!!11') @user.should have(1).comments end admin_user = User.generate! do |user| user.activate! user.add_role(&quot;admin&quot;) end User.spawn  # User.new
Object Daddy ,[object Object]
automatically creates objects for required relationships
relationships are always saved, regardless if you use spawn or generate
Factory Girl http://blog.adsdevshop.com/2009/02/23/factories-for-test-objects-use-them/ http://giantrobots.thoughtbot.com/2008/6/6/waiting-for-a-factory-girl http://www.thoughtbot.com/projects/factory_girl http://dev.thoughtbot.com/factory_girl/ http://github.com/thoughtbot/factory_girl/
Factory Girl Factory.define :user do |f| f.first_name 'John' f.last_name  'Smith' f.admin  false f.email  { Factory.next(:email) } f.email { |u| &quot;#{u.first_name}.#{u.last_name}@example.com&quot; } end Factory.sequence :email do |n| &quot;somebody#{n}@example.com&quot; end f.sequence(:email) { |n| &quot;person#{n}@example.com&quot; }

Más contenido relacionado

La actualidad más candente

Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5osa_ora
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in RailsBenjamin Vandgrift
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds LsArrrrCamp
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesjerryorr
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsRachael L Moore
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsRachael L Moore
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecJoseph Wilk
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming Enguest9bcef2f
 
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]Chris Toohey
 
Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)Eric Satterwhite
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 WebJoseph Wilk
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Confneal_kemp
 
MidwestJS Zero to Testing
MidwestJS Zero to TestingMidwestJS Zero to Testing
MidwestJS Zero to Testingpamselle
 
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...Codemotion
 

La actualidad más candente (18)

QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5
 
Survey of Front End Topics in Rails
Survey of Front End Topics in RailsSurvey of Front End Topics in Rails
Survey of Front End Topics in Rails
 
Metaprogramming + Ds Ls
Metaprogramming + Ds LsMetaprogramming + Ds Ls
Metaprogramming + Ds Ls
 
Turn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modulesTurn your spaghetti code into ravioli with JavaScript modules
Turn your spaghetti code into ravioli with JavaScript modules
 
Cucumber
CucumberCucumber
Cucumber
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web Components
 
Creating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web ComponentsCreating GUI container components in Angular and Web Components
Creating GUI container components in Angular and Web Components
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and Rspec
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
Non Conventional Android Programming En
Non Conventional Android Programming EnNon Conventional Android Programming En
Non Conventional Android Programming En
 
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
 
Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)
 
Cucumber Ru09 Web
Cucumber Ru09 WebCucumber Ru09 Web
Cucumber Ru09 Web
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
MidwestJS Zero to Testing
MidwestJS Zero to TestingMidwestJS Zero to Testing
MidwestJS Zero to Testing
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
The Web Components interoperability challenge - Horacio Gonzalez - Codemotion...
 

Similar a Fixture Replacement Plugins

What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesTikal Knowledge
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)Carles Farré
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend FrameworkBrett Harris
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsJohn Brunswick
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to youguestdd9d06
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplicationolegmmiller
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and DashboardsAtlassian
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosIgor Sobreira
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 
Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Jason Morrison
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecordMark Menard
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rob
 

Similar a Fixture Replacement Plugins (20)

What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Rush, a shell that will yield to you
Rush, a shell that will yield to youRush, a shell that will yield to you
Rush, a shell that will yield to you
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Fixture Replacement Plugins

  • 1. Fixture replacement plugins Jakub Suder Lunar Logic Polska
  • 2. Why fixtures aren't enough „Rails test fixtures are evil and a plague upon developers.” http://b.logi.cx/2007/11/26/object-daddy „If you are still using fixtures, there is no hope for you. Become a forest ranger.” http://blog.adsdevshop.com/2009/02/23/factories-for-test-objects-use-them/
  • 3.
  • 4. no one remembers the „story” it &quot;should be possible to delete a folder only in a group that you're a member of&quot; do folder = folders(:ruby) folder.should be_deletable_by(users(:joe)) folder.should be_deletable_by(users(:joan)) folder.should_not be_deletable_by(users(:bill)) end
  • 5.
  • 6. fixtures can be invalid
  • 7. some things are much more difficult than they should be
  • 10.
  • 11.
  • 13.
  • 18.
  • 19. FixtureReplacement (db/example_data.rb) module FixtureReplacement attributes_for :user do |u| password = String.random u.value = &quot;a value&quot;, u.other = &quot;other value&quot;, u.another = String.random, # random string 10 characters long u.one_more = String.random(15), # 15 characters long u.password = password, u.password_confirmation = password, u.associated_object = default_bar # expects attributes_for :bar end end
  • 20.
  • 23. default_user -> for use inside model_attributes definitions
  • 25. john = create_user(:username => &quot;john&quot;)
  • 26. circumvents attr_protected by assigning manually
  • 27.
  • 28. Object Daddy class User < ActiveRecord::Base generator_for :email, :start => 'test@domain.com' do |prev| user, domain = prev.split('@') user.succ + '@' + domain end generator_for :username, :method => :next_user generator_for :name, :start => 'Joe' generator_for(:start_time) { Time.now } generator_for :name, 'Joe' generator_for :age => 25 def self.next_user @last_username ||= 'testuser' @last_username.succ end end
  • 29. Object Daddy class User < ActiveRecord::Base generator_for :ssn, :class => SSNGenerator end class SSNGenerator def self.next @last ||= '000-00-0000' @last = (&quot;%09d&quot; % (@last.gsub('-', '').to_i + 1)).sub(/^({3})({2})({4})$/, '--') end end
  • 30. Object Daddy it &quot;should have a comment for every forum the user posts to&quot; do @user = User.generate @post = Post.generate @post.comments << Comment.generate(:title => 'first post!!11') @user.should have(1).comments end admin_user = User.generate! do |user| user.activate! user.add_role(&quot;admin&quot;) end User.spawn # User.new
  • 31.
  • 32. automatically creates objects for required relationships
  • 33. relationships are always saved, regardless if you use spawn or generate
  • 34. Factory Girl http://blog.adsdevshop.com/2009/02/23/factories-for-test-objects-use-them/ http://giantrobots.thoughtbot.com/2008/6/6/waiting-for-a-factory-girl http://www.thoughtbot.com/projects/factory_girl http://dev.thoughtbot.com/factory_girl/ http://github.com/thoughtbot/factory_girl/
  • 35. Factory Girl Factory.define :user do |f| f.first_name 'John' f.last_name 'Smith' f.admin false f.email { Factory.next(:email) } f.email { |u| &quot;#{u.first_name}.#{u.last_name}@example.com&quot; } end Factory.sequence :email do |n| &quot;somebody#{n}@example.com&quot; end f.sequence(:email) { |n| &quot;person#{n}@example.com&quot; }
  • 36. Factory Girl Factory.define :admin_user, :class => User do |f| f.first_name 'Bill' f.last_name 'Adminsky' f.email { Factory.next(:email) } f.admin true end Factory.define :admin, :parent => :user do |f| f.admin true end Factory.define :post do |f| f.title 'help!' f.approved true f.author { |a| a.association(:user [, :first_name => ...]) } # or: f.association :author [, :factory => :user] end
  • 37. Factory Girl should &quot;only find approved posts&quot; do Factory(:post, :approved => false) Factory(:post, :approved => true) posts = Post.approved assert posts.all? { |p| p.approved? } end @post = Factory.build(:post, :title => '') # Post.new user_attributes = Factory.attributes_for(:user) # hash
  • 38.
  • 40. saved associations for saved records, and unsaved associations for unsaved records
  • 42.
  • 43.
  • 46. Machinist # /spec/blueprints.rb, /test/blueprints.rb Business.blueprint do name { &quot;My Company&quot; } address { &quot;New York&quot; } web { &quot;http://www.example.com&quot; } email { &quot;info@example.com&quot; } end business = Business.make invalid_business = Business.make(:email => &quot;bad@email&quot;) Business.make_unsaved Business.plan # hash
  • 47. Machinist User.blueprint do email { Sham.email } # or just: email end Sham.email { something random } Sham.invoice_no { |index| &quot;20080101-#{index}&quot; } Sham.name { Faker::Name.name } # http://faker.rubyforge.org/ Faker::Company.name Faker::Internet.email Faker::Internet.domain_name Faker::Lorem.sentence
  • 48. Machinist User.blueprint do name { Sham.name } email { Sham.email } business { Business.make(:name => &quot;#{name} Shop&quot;) } # or just: business end
  • 49.
  • 51. Factory Girl as Machinist require 'factory_girl/syntax/sham' require 'factory_girl/syntax/make' require 'factory_girl/syntax/blueprint' User.blueprint do name { 'John Smith' } email { 'john.smith@gmail.com' } end User.make(:name => 'Johnny') Sham.email { |n| &quot;somebody#{n}@example.com&quot; } # this isn't a real Sham!
  • 52.
  • 53. don't confuse with dm-sweatshop!
  • 54. generates factory girl or machinist configurations
  • 55.
  • 57. DM-Sweatshop User.fixture {{ # or User.fix :username => (username = /+/.gen), :email => &quot;#{username}@example.com&quot;, :password => (password = /+/.gen), :pasword_confirmation => password }} User.fixture(:admin) {{ … }} User.generate :username => 'foo' # or User.gen User.generate(:admin) User.make # unsaved User.generate_attributes # hash
  • 58. DM-Sweatshop User.fixture {{ :email_addresses => 10.of { EmailAddress.make } }} Marker.fixture {{ :categories => 5.of { Category.pick } # or: (2..8).of { Category.pick } }} User.fixture {{ :name => unique { something random }, :login => unique { |i| &quot;user#{i}&quot; } }}
  • 59.
  • 61.
  • 62. – no attr_protected
  • 63. – no way to set one field based on another field
  • 64.
  • 65. + sequences based on index
  • 66. + setting fields based on other fields
  • 67. + multiple factories for one class
  • 68. + factory inheritance
  • 69. + different syntax styles
  • 70.
  • 71. + sequences based on index (but not inline)
  • 72. + setting fields based on other fields
  • 73. + Sham & Faker
  • 74. + multiple factories for one class
  • 75. – no factory inheritance
  • 76.
  • 77. + unique (but non-deterministic) random values
  • 78. + setting fields based on other fields
  • 79. + multiple factories for one class
  • 80. + generating values from regular expressions
  • 83. * DataMapper only
  • 84. – no factory inheritance