source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/grouped_collection_select_input_test.rb
Ruby
mit
8,220
main
6,406
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class GroupedCollectionSelectInputTest < ActionView::TestCase test 'grouped collection accepts array collection form' do with_input_for @user, :tag_ids, :grouped_select, collection: [['Authors', %w[Jose Carlos]], ['General', %w[Bob John]...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/collection_radio_buttons_input_test.rb
Ruby
mit
8,220
main
17,710
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class CollectionRadioButtonsInputTest < ActionView::TestCase test 'input generates boolean radio buttons by default for radio types' do with_input_for @user, :active, :radio_buttons assert_select 'input[type=radio][value=true].radio_button...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/datetime_input_test.rb
Ruby
mit
8,220
main
6,259
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' # Tests for datetime, date and time inputs when HTML5 compatibility is enabled in the wrapper. class DateTimeInputWithHtml5Test < ActionView::TestCase test 'input generates a datetime input for datetime attributes if HTML5 compatibility is explici...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/readonly_test.rb
Ruby
mit
8,220
main
4,052
# frozen_string_literal: true require 'test_helper' class ReadonlyTest < ActionView::TestCase test 'string input generates readonly elements when readonly option is true' do with_input_for @user, :name, :string, readonly: true assert_select 'input.string.readonly[readonly]' end test 'text input generate...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/numeric_input_test.rb
Ruby
mit
8,220
main
6,153
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class NumericInputTest < ActionView::TestCase test 'input generates an integer text field for integer attributes ' do with_input_for @user, :age, :integer assert_select 'input[type=number].integer#user_age' end test 'input generates a...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/disabled_test.rb
Ruby
mit
8,220
main
3,501
# frozen_string_literal: true require 'test_helper' class DisabledTest < ActionView::TestCase test 'string input is disabled when disabled option is true' do with_input_for @user, :name, :string, disabled: true assert_select 'input.string.disabled[disabled]' end test 'text input is disabled when disable...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/required_test.rb
Ruby
mit
8,220
main
6,138
# frozen_string_literal: true require 'test_helper' class RequiredTest < ActionView::TestCase # REQUIRED AND PRESENCE VALIDATION test 'builder input obtains required from ActiveModel::Validations when it is included' do with_form_for @validating_user, :name assert_select 'input.required[required]#validatin...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/color_input_test.rb
Ruby
mit
8,220
main
264
# frozen_string_literal: true require 'test_helper' class ColorInputTest < ActionView::TestCase test 'input generates a color field' do with_input_for @user, :favorite_color, :color assert_select 'input[type=color].color#user_favorite_color' end end
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/string_input_test.rb
Ruby
mit
8,220
main
6,189
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class StringInputTest < ActionView::TestCase test 'input maps text field to string attribute' do with_input_for @user, :name, :string assert_select "input#user_name[type=text][name='user[name]'][value='New in SimpleForm!']" end test '...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/file_input_test.rb
Ruby
mit
8,220
main
514
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class FileInputTest < ActionView::TestCase test 'input generates a file field' do with_input_for @user, :name, :file assert_select 'input#user_name[type=file]' end test "input generates a file field that doesn't accept placeholder" do...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/text_input_test.rb
Ruby
mit
8,220
main
1,505
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class TextInputTest < ActionView::TestCase test 'input generates a text area for text attributes' do with_input_for @user, :description, :text assert_select 'textarea.text#user_description' end test 'input generates a text area for te...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/collection_check_boxes_input_test.rb
Ruby
mit
8,220
main
12,403
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class CollectionCheckBoxesInputTest < ActionView::TestCase test 'input check boxes does not include for attribute by default' do with_input_for @user, :gender, :check_boxes, collection: %i[male female] assert_select 'label' assert_no_s...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/weekday_input_test.rb
Ruby
mit
8,220
main
487
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class WeekdayInputTest < ActionView::TestCase test 'input generates a weekday select' do with_input_for @user, :born_at, :weekday assert_select 'select.weekday#user_born_at' end test 'input generates a weekday select that accepts plac...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/boolean_input_test.rb
Ruby
mit
8,220
main
10,361
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class BooleanInputTest < ActionView::TestCase test 'input generates a checkbox by default for boolean attributes' do with_input_for @user, :active, :boolean assert_select 'input[type=checkbox].boolean#user_active' assert_select 'label....
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/discovery_test.rb
Ruby
mit
8,220
main
4,583
# frozen_string_literal: true require 'test_helper' class DiscoveryTest < ActionView::TestCase # Setup new inputs and remove them after the test. def discovery(value = false) swap SimpleForm, cache_discovery: value do begin load "support/discovery_inputs.rb" yield ensure Sim...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/rich_text_area_input_test.rb
Ruby
mit
8,220
main
525
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class RichTextAreaInputTest < ActionView::TestCase test 'input generates a text area for text attributes' do with_input_for @user, :description, :text assert_select 'textarea.text#user_description' end test 'input generates a text are...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/general_test.rb
Ruby
mit
8,220
main
4,968
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class InputTest < ActionView::TestCase test 'input generates css class based on default input type' do with_input_for @user, :name, :string assert_select 'input.string' with_input_for @user, :description, :text assert_select 'texta...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/inputs/collection_select_input_test.rb
Ruby
mit
8,220
main
15,646
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' class CollectionSelectInputTest < ActionView::TestCase test 'input generates a boolean select with options by default for select types' do with_input_for @user, :active, :select assert_select 'select.select#user_active' assert_select '...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/components/custom_components_test.rb
Ruby
mit
8,220
main
1,882
# frozen_string_literal: true require 'test_helper' # Module that represents a custom component. module Numbers def number(wrapper_options = nil) @number ||= options[:number].to_s.html_safe end end # Module that represents a custom component. module InputGroup def prepend(wrapper_options = nil) span_ta...
github
heartcombo/simple_form
https://github.com/heartcombo/simple_form
test/components/label_test.rb
Ruby
mit
8,220
main
12,938
# frozen_string_literal: true # encoding: UTF-8 require 'test_helper' # Isolated tests for label without triggering f.label. class IsolatedLabelTest < ActionView::TestCase def with_label_for(object, attribute_name, type, options = {}) with_concat_form_for(object) do |f| options[:reflection] = Association.n...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
Rakefile
Ruby
mit
8,193
main
927
require "rubygems" require "bundler" require "rake" require "yard" require "rspec/core/rake_task" require "cucumber/rake/task" require "standard/rake" Bundler::GemHelper.install_tasks(name: "factory_bot") desc "Default: run all specs and standard" task default: %w[all_specs standard] desc "Run all specs and features...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
Appraisals
Ruby
mit
8,193
main
1,190
appraise "6.1" do gem "activerecord", "~> 6.1.0" gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platforms: [:jruby] gem "sqlite3", "~> 1.4", platforms: [:ruby] gem "concurrent-ruby", "< 1.3.5" end appraise "7.0" do gem "activerecord", "~> 7.0.0" gem "activerecord-jdbcsqlite3-adapter", "~> 70.0", platfo...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
factory_bot.gemspec
Ruby
mit
8,193
main
1,592
$LOAD_PATH << File.expand_path("lib", __dir__) require "factory_bot/version" Gem::Specification.new do |s| s.name = "factory_bot" s.version = FactoryBot::VERSION s.summary = "factory_bot provides a framework and DSL for defining and " \ "using model instance factories." s.description = "facto...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot_spec.rb
Ruby
mit
8,193
main
361
describe FactoryBot do it "finds a registered strategy" do FactoryBot.register_strategy(:strategy_name, :strategy_class) expect(FactoryBot.strategy_by_name(:strategy_name)) .to eq :strategy_class end describe ".use_parent_strategy" do it "is true by default" do expect(FactoryBot.use_paren...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/spec_helper.rb
Ruby
mit
8,193
main
995
# Set timeout when setting sequences require "rspec" require "rspec/its" require "simplecov" if RUBY_ENGINE == "ruby" require "factory_bot" FactoryBot.sequence_setting_timeout = 0.5 if RUBY_ENGINE == "jruby" # Workaround for issue in I18n/JRuby combo. # See https://github.com/jruby/jruby/issues/6547 and # htt...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/registry_spec.rb
Ruby
mit
8,193
main
3,254
describe FactoryBot::Registry do it "is an enumerable" do registry = FactoryBot::Registry.new("Great thing") expect(registry).to be_kind_of(Enumerable) end it "finds a registered object" do registry = FactoryBot::Registry.new("Great thing") registered_object = double("registered object") reg...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/find_definitions_spec.rb
Ruby
mit
8,193
main
3,844
require "fileutils" shared_examples_for "finds definitions" do before do allow(FactoryBot).to receive(:load) FactoryBot.find_definitions end subject { FactoryBot } end RSpec::Matchers.define :load_definitions_from do |file| match do |given| @has_received = have_received(:load).with(File.expand_pa...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/declaration_list_spec.rb
Ruby
mit
8,193
main
3,778
describe FactoryBot::DeclarationList, "#attributes" do it "returns an AttributeList" do declaration_list = FactoryBot::DeclarationList.new expect(declaration_list.attributes).to be_a(FactoryBot::AttributeList) end it "defines each attribute on the attribute list" do attribute1 = double("attribute 1"...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/internal_spec.rb
Ruby
mit
8,193
main
4,682
describe FactoryBot::Internal do describe ".register_trait" do it "registers the provided trait" do trait = FactoryBot::Trait.new(:admin) configuration = FactoryBot::Internal.configuration expect { FactoryBot::Internal.register_trait(trait) } .to change { configuration.traits.count } ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute_assignment_spec.rb
Ruby
mit
8,193
main
1,370
describe "Attribute Assignment" do it "sets the <attribute> default value if not overridden" do name = :user define_class("User") { attr_accessor :name, :response } factory = FactoryBot::Factory.new(name) FactoryBot::Internal.register_factory(factory) attr_1 = FactoryBot::Declaration::Dynamic.new...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/evaluator_class_definer_spec.rb
Ruby
mit
8,193
main
2,392
describe FactoryBot::EvaluatorClassDefiner do it "returns an evaluator when accessing the evaluator class" do evaluator = define_evaluator(parent_class: FactoryBot::Evaluator) expect(evaluator).to be_a(FactoryBot::Evaluator) end it "adds each attribute to the evaluator" do attribute = stub_attribute...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/strategy_spec.rb
Ruby
mit
8,193
main
876
describe FactoryBot::Strategy do it "returns the class passed when it is instantiated with a class" do strategy = define_class("MyAwesomeClass") result = described_class.lookup_strategy(strategy) expect(result).to eq strategy end it "finds the strategy by name when instantiated with a symbol" do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/definition_spec.rb
Ruby
mit
8,193
main
2,412
describe FactoryBot::Definition do it "delegates :declare_attribute to declarations" do definition = described_class.new(:name) expect(definition).to delegate(:declare_attribute).to(:declarations) end it "creates a new attribute list with the name passed when given a name" do name = "great name" ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/definition_proxy_spec.rb
Ruby
mit
8,193
main
10,474
describe FactoryBot::DefinitionProxy, "#add_attribute" do it "declares a dynamic attribute on the factory when the proxy respects attributes" do definition = FactoryBot::Definition.new(:name) proxy = FactoryBot::DefinitionProxy.new(definition) attribute_value = -> { "dynamic attribute" } proxy.add_att...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/aliases_spec.rb
Ruby
mit
8,193
main
943
describe FactoryBot, "aliases" do it "for an attribute should include the original attribute and a version suffixed with '_id'" do aliases = FactoryBot.aliases_for(:test) expect(aliases).to include(:test, :test_id) end it "for a foreign key should include both the suffixed and un-suffixed variants" do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute_list_spec.rb
Ruby
mit
8,193
main
5,405
module AttributeList def build_attribute_list(*attributes) FactoryBot::AttributeList.new.tap do |list| attributes.each { |attribute| list.define_attribute(attribute) } end end end describe FactoryBot::AttributeList, "#define_attribute" do it "maintains a list of attributes" do attribute = doubl...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/callback_spec.rb
Ruby
mit
8,193
main
865
describe FactoryBot::Callback do it "has a name" do expect(FactoryBot::Callback.new(:after_create, -> {}).name).to eq :after_create end it "converts strings to symbols" do expect(FactoryBot::Callback.new("after_create", -> {}).name).to eq :after_create end it "runs its block with no parameters" do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/null_factory_spec.rb
Ruby
mit
8,193
main
1,439
describe FactoryBot::NullFactory do it "delegates defined traits to its definition" do null_factory = FactoryBot::NullFactory.new expect(null_factory).to delegate(:defined_traits).to(:definition) end it "delegates callbacks to its definition" do null_factory = FactoryBot::NullFactory.new expect...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/null_object_spec.rb
Ruby
mit
8,193
main
803
describe FactoryBot::NullObject do it "responds to the given methods" do methods_to_respond_to = %w[id age name admin?] null_object = FactoryBot::NullObject.new(methods_to_respond_to) methods_to_respond_to.each do |method_name| expect(null_object.__send__(method_name)).to be_nil expect(null_o...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute_spec.rb
Ruby
mit
8,193
main
370
describe FactoryBot::Attribute do it "converts the name attribute to a symbol" do name = "user" attribute = FactoryBot::Attribute.new(name, false) expect(attribute.name).to eq name.to_sym end it "is not an association" do name = "user" attribute = FactoryBot::Attribute.new(name, false) ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/factory_spec.rb
Ruby
mit
8,193
main
10,509
describe FactoryBot::Factory do it "has a factory name" do name = :user factory = FactoryBot::Factory.new(name) FactoryBot::Internal.register_factory(factory) expect(factory.name).to eq name end it "has a build class" do name = :user klass = define_class("User") factory = FactoryBot:...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/sequence_spec.rb
Ruby
mit
8,193
main
7,027
shared_examples "a sequence" do |options| first_value = options[:first_value] second_value = options[:second_value] it "has a next value equal to its first value" do expect(subject.next).to eq first_value end it "has a next value equal to the 2nd value after being incremented" do subject.next e...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/disallows_duplicates_registry_spec.rb
Ruby
mit
8,193
main
914
describe FactoryBot::Decorator::DisallowsDuplicatesRegistry do it "delegates #register to the registry when not registered" do registry = double("registry", name: "Great thing", register: true) decorator = FactoryBot::Decorator::DisallowsDuplicatesRegistry.new(registry) allow(registry).to receive(:registe...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/uri_manager_spec.rb
Ruby
mit
8,193
main
3,614
describe FactoryBot::UriManager do describe ".build_uri" do it "combines the parts to form a Symbol" do expect(described_class.build_uri(:ep1, :ep2, :ep3)) .to eq :"ep1/ep2/ep3" end it "works with a single part" do expect(described_class.build_uri(:ep1)) .to eq :ep1 end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/decorator/attribute_hash_spec.rb
Ruby
mit
8,193
main
718
describe FactoryBot::Decorator::AttributeHash do describe "#attributes" do it "returns a hash of attributes" do attributes = {attribute_1: :value, attribute_2: :value} component = double(:component, attributes) decorator = described_class.new(component, [:attribute_1, :attribute_2]) expe...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/declaration/implicit_spec.rb
Ruby
mit
8,193
main
2,857
describe FactoryBot::Declaration::Implicit do context "with a known factory" do it "creates an association attribute" do allow(FactoryBot.factories).to receive(:registered?).and_return true declaration = FactoryBot::Declaration::Implicit.new(:name) attribute = declaration.to_attributes.first ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/declaration/dynamic_spec.rb
Ruby
mit
8,193
main
1,574
describe FactoryBot::Declaration::Dynamic do describe "#==" do context "when the attributes are equal" do it "the objects are equal" do block = -> {} declaration = described_class.new(:name, false, block) other_declaration = described_class.new(:name, false, block) expect(de...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/declaration/association_spec.rb
Ruby
mit
8,193
main
1,206
describe FactoryBot::Declaration::Association do describe "#==" do context "when the attributes are equal" do it "the objects are equal" do declaration = described_class.new(:name, options: true) other_declaration = described_class.new(:name, options: true) expect(declaration).to eq...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute/dynamic_spec.rb
Ruby
mit
8,193
main
1,865
describe FactoryBot::Attribute::Dynamic do let(:name) { :first_name } let(:block) { -> {} } subject { FactoryBot::Attribute::Dynamic.new(name, false, block) } its(:name) { should eq name } context "with a block returning a static value" do let(:block) { -> { "value" } } it "returns the value when ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute/association_spec.rb
Ruby
mit
8,193
main
1,143
describe FactoryBot::Attribute::Association do let(:name) { :author } let(:factory) { :user } let(:overrides) { {first_name: "John"} } let(:association) { double("association") } subject { FactoryBot::Attribute::Association.new(name, factory, overrides) } before do # Define an '#association' instance ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/attribute/sequence_spec.rb
Ruby
mit
8,193
main
471
describe FactoryBot::Attribute::Sequence do let(:sequence_name) { :name } let(:name) { :first_name } let(:sequence) { FactoryBot::Sequence.new(sequence_name, 5) { |n| "Name #{n}" } } subject { FactoryBot::Attribute::Sequence.new(name, sequence_name, false) } before { FactoryBot::Internal.register_sequence(se...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/strategy/create_spec.rb
Ruby
mit
8,193
main
447
describe FactoryBot::Strategy::Create do it_should_behave_like "strategy with association support", :create it_should_behave_like "strategy with callbacks", :after_build, :before_create, :after_create it "runs a custom create block" do evaluation = double( "evaluation", object: nil, notify:...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/strategy/build_spec.rb
Ruby
mit
8,193
main
242
describe FactoryBot::Strategy::Build do it_should_behave_like "strategy with association support", :create it_should_behave_like "strategy with callbacks", :after_build it_should_behave_like "strategy with strategy: :build", :build end
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/strategy/stub_spec.rb
Ruby
mit
8,193
main
2,665
shared_examples "disabled persistence method" do |method_name| let(:instance) { described_class.new.result(evaluation) } describe "overriding persistence method: ##{method_name}" do it "overrides the method with any arity" do method = instance.method(method_name) expect(method.arity).to eq(-1) ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/factory_bot/strategy/attributes_for_spec.rb
Ruby
mit
8,193
main
469
describe FactoryBot::Strategy::AttributesFor do let(:result) { {name: "John Doe", gender: "Male", admin: false} } let(:evaluation) { double("evaluation", hash: result) } it_should_behave_like "strategy without association support" it "returns the hash from the evaluation" do expect(subject.result(evaluati...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/transient_attributes_spec.rb
Ruby
mit
8,193
main
3,511
describe "transient attributes" do before do define_model("User", name: :string, email: :string) FactoryBot.define do sequence(:name) { |n| "John #{n}" } factory :user do transient do four { 2 + 2 } rockstar { true } upcased { false } end na...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/global_initialize_with_spec.rb
Ruby
mit
8,193
main
2,047
describe "global initialize_with" do before do define_class("User") do attr_accessor :name def initialize(name) @name = name end end define_class("Post") do attr_reader :name def initialize(name) @name = name end end FactoryBot.define do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/activesupport_instrumentation_spec.rb
Ruby
mit
8,193
main
9,270
unless ActiveSupport::Notifications.respond_to?(:subscribed) module SubscribedBehavior def subscribed(callback, *args) subscriber = subscribe(*args, &callback) yield ensure unsubscribe(subscriber) end end ActiveSupport::Notifications.extend SubscribedBehavior end describe "using Ac...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/definition_camel_string_spec.rb
Ruby
mit
8,193
main
353
describe "an instance generated by a factory named a camel case string " do before do define_model("UserModel") FactoryBot.define do factory "UserModel", class: UserModel end end it "registers the UserModel factory" do expect(FactoryBot::Internal.factory_by_name("UserModel")) .to be_...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/definition_without_block_spec.rb
Ruby
mit
8,193
main
286
describe "an instance generated by a factory" do before do define_model("User") FactoryBot.define do factory :user end end it "registers the user factory" do expect(FactoryBot::Internal.factory_by_name(:user)) .to be_a(FactoryBot::Factory) end end
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/associations_spec.rb
Ruby
mit
8,193
main
4,068
describe "associations" do context "when accidentally using an implicit declaration for the factory" do it "raises an error" do define_class("Post") FactoryBot.define do factory :post do author factory: user end end expect { FactoryBot.build(:post) }.to raise_er...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/add_attribute_spec.rb
Ruby
mit
8,193
main
1,022
describe "#add_attribute" do it "assigns attributes for reserved words on .build" do define_model("Post", title: :string, sequence: :string, new: :boolean) FactoryBot.define do factory :post do add_attribute(:title) { "Title" } add_attribute(:sequence) { "Sequence" } add_attribu...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attribute_existing_on_object_spec.rb
Ruby
mit
8,193
main
1,757
describe "declaring attributes on a Factory that are private methods on Object" do before do define_model("Website", system: :boolean, link: :string, sleep: :integer) FactoryBot.define do factory :website do system { false } link { "http://example.com" } sleep { 15 } end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/modify_factories_spec.rb
Ruby
mit
8,193
main
4,468
describe "modifying factories" do include FactoryBot::Syntax::Methods before do define_model("User", name: :string, admin: :boolean, email: :string, login: :string) FactoryBot.define do sequence(:email) { |n| "user#{n}@example.com" } factory :user do email after(:create) do |...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/lint_spec.rb
Ruby
mit
8,193
main
5,497
describe "FactoryBot.lint" do it "raises when a factory is invalid" do define_model "User", name: :string do validates :name, presence: true end define_model "AlwaysValid" FactoryBot.define do factory :user do factory :admin_user end factory :always_valid end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attributes_from_instance_spec.rb
Ruby
mit
8,193
main
1,443
describe "calling methods on the model instance" do before do define_model("User", age: :integer, age_copy: :integer) do def age read_attribute(:age) || 18 end end FactoryBot.define do factory :user do age_copy { age } end end end context "without the attr...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/skip_create_spec.rb
Ruby
mit
8,193
main
356
describe "skipping the default create" do before do define_model("User", email: :string) FactoryBot.define do factory :user do skip_create email { "john@example.com" } end end end it "doesn't execute anything when creating the instance" do expect(FactoryBot.create(:u...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/create_spec.rb
Ruby
mit
8,193
main
2,601
describe "a created instance" do include FactoryBot::Syntax::Methods before do define_model("User") define_model("Post", user_id: :integer) do belongs_to :user end FactoryBot.define do factory :user factory :post do user end end end subject { create("post...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/defining_methods_inside_a_factory_spec.rb
Ruby
mit
8,193
main
832
describe "defining methods inside FactoryBot" do it "raises with a meaningful message" do define_model("User") bad_factory_definition = -> do FactoryBot.define do factory :user do def generate_name "John Doe" end end end end expect(&bad_fac...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/create_pair_spec.rb
Ruby
mit
8,193
main
701
describe "create multiple instances" do before do define_model("Post", title: :string, position: :integer) FactoryBot.define do factory(:post) do |post| post.title { "Through the Looking Glass" } post.position { rand(10**4) } end end end context "without default attribute...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/enum_traits_spec.rb
Ruby
mit
8,193
main
4,220
describe "enum traits" do def define_model_with_enum(class_name, field, values) define_model(class_name, status: :integer) do if ActiveRecord::VERSION::STRING >= "7.0" enum field, values else enum field => values end end end context "when automatically_define_enum_traits...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/initialize_with_spec.rb
Ruby
mit
8,193
main
6,102
describe "initialize_with with non-FG attributes" do include FactoryBot::Syntax::Methods before do define_model("User", name: :string, age: :integer) do def self.construct(name, age) new(name: name, age: age) end end FactoryBot.define do factory :user do initialize_wi...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/reload_spec.rb
Ruby
mit
8,193
main
329
describe "reload" do it "does not reset the value of use_parent_strategy" do custom_strategy = :custom_use_parent_strategy_value with_temporary_assignment(FactoryBot, :use_parent_strategy, custom_strategy) do FactoryBot.reload expect(FactoryBot.use_parent_strategy).to eq custom_strategy end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/global_to_create_spec.rb
Ruby
mit
8,193
main
3,240
describe "global to_create" do before do define_model("User", name: :string) define_model("Post", name: :string) FactoryBot.define do to_create { |instance| instance.name = "persisted!" } trait :override_to_create do to_create { |instance| instance.name = "override" } end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/sequence_setting_spec.rb
Ruby
mit
8,193
main
12,333
describe "FactoryBot.set_sequence" do include FactoryBot::Syntax::Methods describe "on success" do describe "setting sequence to correct value" do it "works with Integer sequences" do FactoryBot.define do sequence(:email) { |n| "somebody#{n}@example.com" } end expect(ge...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attributes_for_spec.rb
Ruby
mit
8,193
main
2,229
if RUBY_ENGINE != "truffleruby" require_relative "attributes_for_destructuring" end describe "a generated attributes hash" do include FactoryBot::Syntax::Methods before do define_model("User") define_model("Comment") define_model("Post", title: :string, body: :string, summary: :string, ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/modify_inherited_spec.rb
Ruby
mit
8,193
main
1,368
describe "modifying inherited factories with traits" do before do define_model("User", gender: :string, admin: :boolean, age: :integer) FactoryBot.define do factory :user do trait(:female) { gender { "Female" } } trait(:male) { gender { "Male" } } trait(:young_admin) do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/nested_attributes_spec.rb
Ruby
mit
8,193
main
880
describe "association assignment from nested attributes" do before do define_model("Post", title: :string) do has_many :comments accepts_nested_attributes_for :comments end define_model("Comment", post_id: :integer, body: :text) do belongs_to :post end FactoryBot.define do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/define_child_before_parent_spec.rb
Ruby
mit
8,193
main
456
describe "defining a child factory before a parent" do before do define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string) FactoryBot.define do factory :admin, parent: :user do admin { true } end factory :user do name { "awes...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/definition_spec.rb
Ruby
mit
8,193
main
1,223
describe "an instance generated by a factory with a custom class name" do before do define_model("User", admin: :boolean) FactoryBot.define do factory :user factory :admin, class: User do admin { true } end end end subject { FactoryBot.create(:admin) } it { should be_ki...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/traits_spec.rb
Ruby
mit
8,193
main
25,388
describe "an instance generated by a factory with multiple traits" do before do define_model("User", name: :string, admin: :boolean, gender: :string, email: :string, date_of_birth: :date, great: :string) FactoryBot.define do factory :user do name { "John" } ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/overrides_spec.rb
Ruby
mit
8,193
main
1,288
describe "attribute overrides" do before do define_model("User", admin: :boolean) define_model("Post", title: :string, secure: :boolean, user_id: :integer) do belongs_to :user def secure=(value) return unless user&.admin? write_attribute(:secure, value) end ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/sequence_spec.rb
Ruby
mit
8,193
main
6,913
describe "sequences" do include FactoryBot::Syntax::Methods require "ostruct" # = On Success # ====================================================================== # describe "on success" do it "generates several values in the correct format" do define_class("User") { attr_accessor :email } ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/build_list_spec.rb
Ruby
mit
8,193
main
1,702
describe "build multiple instances" do before do define_model("Post", title: :string, position: :integer) FactoryBot.define do factory(:post) do |post| post.title { "Through the Looking Glass" } post.position { rand(10**4) } end end end context "without default attributes...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/build_spec.rb
Ruby
mit
8,193
main
2,086
describe "a built instance" do include FactoryBot::Syntax::Methods before do define_model("User") define_model("Post", user_id: :integer) do belongs_to :user end FactoryBot.define do factory :user factory :post do user end end end subject { build(:post) }...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/create_list_spec.rb
Ruby
mit
8,193
main
2,932
describe "create multiple instances" do before do define_model("Post", title: :string, position: :integer) FactoryBot.define do factory(:post) do |post| post.title { "Through the Looking Glass" } post.position { rand(10**4) } end end end context "without default attribute...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attributes_ordered_spec.rb
Ruby
mit
8,193
main
1,390
describe "a generated attributes hash where order matters" do include FactoryBot::Syntax::Methods before do define_model("ParentModel", static: :integer, evaluates_first: :integer, evaluates_second: :integer, evaluates_third: :integer) FactoryBot.define do factory :parent_model do ...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attribute_aliases_spec.rb
Ruby
mit
8,193
main
13,603
describe "attribute aliases" do around do |example| original_aliases = FactoryBot.aliases.dup example.run ensure FactoryBot.aliases.clear FactoryBot.aliases.concat(original_aliases) end describe "basic alias functionality" do it "allows using different parameter names that map to model attr...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/build_stubbed_spec.rb
Ruby
mit
8,193
main
7,470
describe "a generated stub instance" do include FactoryBot::Syntax::Methods before do define_model("User") define_model("Post", title: :string, body: :string, age: :integer, user_id: :integer, draft: :boolean) do belongs_to :user end FactoryBot.define do factor...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/register_strategies_spec.rb
Ruby
mit
8,193
main
4,003
shared_context "registering custom strategies" do before do define_class("NamedObject") do attr_accessor :name end end let(:custom_strategy) do Class.new do def result(evaluation) evaluation.object.tap do |instance| instance.name = "Custom strategy" end end...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb
Ruby
mit
8,193
main
1,398
describe "syntax methods within dynamic attributes" do before do define_model("Post", title: :string, user_id: :integer) do belongs_to :user def generate "generate result" end end define_model("User", email: :string) FactoryBot.define do sequence(:email_address) { |n|...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/stub_spec.rb
Ruby
mit
8,193
main
4,005
describe "a stubbed instance" do include FactoryBot::Syntax::Methods before do define_model("User") define_model("Post", user_id: :integer) do belongs_to :user end FactoryBot.define do factory :user factory :post do user end end end subject { build_stubbe...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/parent_spec.rb
Ruby
mit
8,193
main
1,684
describe "an instance generated by a factory that inherits from another factory" do before do define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string) FactoryBot.define do factory :user do name { "John" } email { "#{name.downcase}@exampl...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/sequence_context_spec.rb
Ruby
mit
8,193
main
5,874
describe "sequences are evaluated in the correct context, directly & implicitly" do include FactoryBot::Syntax::Methods before do define_class("User") do attr_accessor :id, :name def awesome "aw yeah" end end end it "builds a sequence calling sprintf correctly" do Factor...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/keyed_by_class_spec.rb
Ruby
mit
8,193
main
362
describe "finding factories keyed by class instead of symbol" do before do define_model("User") do attr_accessor :name, :email end FactoryBot.define do factory :user end end it "doesn't find the factory" do expect { FactoryBot.create(User) }.to( raise_error(KeyError, /Facto...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/attributes_for_destructuring.rb
Ruby
mit
8,193
main
625
describe "Ruby 3.0: attributes_for destructuring syntax" do include FactoryBot::Syntax::Methods before do define_model("User", name: :string) FactoryBot.define do factory :user do sequence(:email) { "email_#{_1}@example.com" } name { "John Doe" } end end end it "suppor...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/callbacks_spec.rb
Ruby
mit
8,193
main
16,734
describe "callbacks" do before do define_model("User", first_name: :string, last_name: :string) end context "with strategy callbacks" do before do FactoryBot.define do factory :user_with_callbacks, class: :user do after(:stub) { |user| user.first_name = "Stubby" } after(...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/acceptance/private_attributes_spec.rb
Ruby
mit
8,193
main
334
describe "setting private attributes" do it "raises a NoMethodError" do define_class("User") do private attr_accessor :foo end FactoryBot.define do factory :user do foo { 123 } end end expect { FactoryBot.build(:user) }.to raise_error NoMethodError, /fo...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/support/containers/test_log.rb
Ruby
mit
8,193
main
519
require "forwardable" ## # Designed for tests to log output for later evaluation # module TestLog class << self extend Forwardable def_delegators :log_array, :<<, :[], :size, :first, :last def_delegators :log_array, :map, :in?, :include?, :inspect def all Thread.current[:my_thread_safe_test_l...
github
thoughtbot/factory_bot
https://github.com/thoughtbot/factory_bot
spec/support/macros/temporary_assignment.rb
Ruby
mit
8,193
main
407
module TemporaryAssignment def with_temporary_assignment(assignee, attribute, temporary_value) original_value = assignee.public_send(attribute) attribute_setter = "#{attribute}=" assignee.public_send(attribute_setter, temporary_value) yield ensure assignee.public_send(attribute_setter, original_...