sixarm_ruby_factory_girl_test_examples

SixArm.com » Ruby » Factory Girl test examples for Rails

https://github.com/sixarm/sixarm_ruby_factory_girl_test_examples

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.8%) to scientific vocabulary

Keywords

factory factory-girl gem ruby test
Last synced: 4 months ago · JSON representation ·

Repository

SixArm.com » Ruby » Factory Girl test examples for Rails

Basic Info
  • Host: GitHub
  • Owner: SixArm
  • License: other
  • Language: Ruby
  • Default Branch: main
  • Homepage: http://sixarm.com
  • Size: 32.2 KB
Statistics
  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
factory factory-girl gem ruby test
Created almost 15 years ago · Last pushed 9 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Codeowners

README.md

SixArm.com → Ruby →
Factory Girl test examples for Rails

Introduction

Factory Girl examples for the ThoughtBot factory_girl gem. These are useful for our testing Ruby On Rails applications.

For docs go to http://sixarm.com/sixarm_ruby_/doc

Want to help? We're happy to get pull requests.

Install

To install using a Gemfile, add this:

gem "", ">= ", "< 1"

To install using the command line, run this:

gem install  -v ">= , < 1"

To install using the command line with high security, run this:

wget http://sixarm.com/sixarm.pem
gem cert --add sixarm.pem && gem sources --add http://sixarm.com
gem install  -v ">= , < 1" --trust-policy HighSecurity

To require the gem in your code:

require ""

Details

These examples are built independent of any mock data tool. You will most likely want to change these examples to suit whichever mock data tool you like to use in your project.

We like these mock data tools:

  • forgery: best for custom dictionaries and generators.
  • faker: best as a straight port of the Perl Faker module.
  • ffaker: faster faker, an optimization of the faker gem.
  • random_data: good for plausible anames, ddresses, etc.

To create a collection of items

Simply call the factory like this:

3.times { Factory(:user) }

To create a collection for the "many" in a has_many

Do it in Factory Girl after_create on the belonging object. So if you wanted a test with a Company with 3 Users:

Factory.define :company_with_three_users do |blog|
  company.after_create do |belonging|
    3.times { Factory(:user, :company => belonging) }
  end
end

To create records that share parameters

Write a helper method:

# in test/factories.rb or spec/factories.rb
def two_companies_for(user = Factory(:user))
  [Factory(:company), Factory(:company)]
end

To connect cucumber steps for dynamic factories

Parse the cucumber step then send the match as a parameter:

Given /^typical (\w+)/ do |name|
  Factory(name)
end

To do more advanced expert setup with callbacks

See this post about callbacks before and after factories:

http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl

Owner

  • Name: SixArm
  • Login: SixArm
  • Kind: organization
  • Email: sixarm@sixarm.com
  • Location: San Francisco

SixArm Software

Citation (CITATION.cff)

cff-version: 1.2.0
title: SixArm.com → Ruby → <br> Factory Girl test examples for Rails
message: >-
  If you use this work and you want to cite it,
  then you can use the metadata from this file.
type: software
authors:
  - given-names: Joel Parker
    family-names: Henderson
    email: joel@joelparkerhenderson.com
    affiliation: joelparkerhenderson.com
    orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
  - type: url
    value: 'https://github.com/SixArm/sixarm_ruby_factory_girl_test_examples/'
    description: SixArm.com → Ruby → <br> Factory Girl test examples for Rails
repository-code: 'https://github.com/SixArm/sixarm_ruby_factory_girl_test_examples/'
abstract: >-
  SixArm.com → Ruby → <br> Factory Girl test examples for Rails
license: See license file

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 56
  • Total Committers: 1
  • Avg Commits per committer: 56.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joel Parker Henderson j****l@j****m 56
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 5 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels