Skip to content
Browse files

Convert to expect syntax

  • Loading branch information...
1 parent 18a5125 commit b095f2459803d74ef04b9d769a004b32ac750b92 @joshuaclayton joshuaclayton committed Jan 18, 2013
Showing with 491 additions and 498 deletions.
  1. +1 −1 GETTING_STARTED.md
  2. +1 −1 features/step_definitions/database_steps.rb
  3. +3 −3 spec/acceptance/activesupport_instrumentation_spec.rb
  4. +1 −1 spec/acceptance/aliases_spec.rb
  5. +3 −3 spec/acceptance/attribute_aliases_spec.rb
  6. +8 −8 spec/acceptance/attribute_existing_on_object_spec.rb
  7. +11 −9 spec/acceptance/attributes_for_spec.rb
  8. +7 −7 spec/acceptance/attributes_from_instance_spec.rb
  9. +6 −6 spec/acceptance/attributes_ordered_spec.rb
  10. +5 −5 spec/acceptance/build_list_spec.rb
  11. +10 −13 spec/acceptance/build_spec.rb
  12. +15 −14 spec/acceptance/build_stubbed_spec.rb
  13. +19 −19 spec/acceptance/callbacks_spec.rb
  14. +7 −7 spec/acceptance/create_list_spec.rb
  15. +10 −11 spec/acceptance/create_spec.rb
  16. +1 −1 spec/acceptance/define_child_before_parent_spec.rb
  17. +2 −7 spec/acceptance/definition_spec.rb
  18. +1 −1 spec/acceptance/definition_without_block_spec.rb
  19. +10 −10 spec/acceptance/global_initialize_with_spec.rb
  20. +18 −18 spec/acceptance/global_to_create_spec.rb
  21. +13 −13 spec/acceptance/initialize_with_spec.rb
  22. +2 −2 spec/acceptance/keyed_by_class_spec.rb
  23. +21 −21 spec/acceptance/modify_factories_spec.rb
  24. +7 −7 spec/acceptance/modify_inherited_spec.rb
  25. +2 −2 spec/acceptance/nested_attributes_spec.rb
  26. +1 −1 spec/acceptance/overrides_spec.rb
  27. +9 −9 spec/acceptance/parent_spec.rb
  28. +9 −9 spec/acceptance/register_strategies_spec.rb
  29. +4 −4 spec/acceptance/sequence_context_spec.rb
  30. +12 −12 spec/acceptance/sequence_spec.rb
  31. +1 −1 spec/acceptance/skip_create_spec.rb
  32. +4 −4 spec/acceptance/stub_spec.rb
  33. +5 −5 spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb
  34. +84 −84 spec/acceptance/traits_spec.rb
  35. +13 −13 spec/acceptance/transient_attributes_spec.rb
  36. +4 −4 spec/factory_girl/attribute/association_spec.rb
  37. +5 −5 spec/factory_girl/attribute/dynamic_spec.rb
  38. +2 −2 spec/factory_girl/attribute/sequence_spec.rb
  39. +3 −3 spec/factory_girl/attribute/static_spec.rb
  40. +12 −12 spec/factory_girl/attribute_list_spec.rb
  41. +1 −1 spec/factory_girl/attribute_spec.rb
  42. +5 −5 spec/factory_girl/callback_spec.rb
  43. +1 −1 spec/factory_girl/declaration/implicit_spec.rb
  44. +11 −11 spec/factory_girl/declaration_list_spec.rb
  45. +20 −20 spec/factory_girl/definition_proxy_spec.rb
  46. +6 −6 spec/factory_girl/definition_spec.rb
  47. +1 −1 spec/factory_girl/disallows_duplicates_registry_spec.rb
  48. +6 −7 spec/factory_girl/evaluator_class_definer_spec.rb
  49. +34 −34 spec/factory_girl/factory_spec.rb
  50. +1 −1 spec/factory_girl/null_factory_spec.rb
  51. +3 −3 spec/factory_girl/null_object_spec.rb
  52. +12 −12 spec/factory_girl/registry_spec.rb
  53. +19 −19 spec/factory_girl/sequence_spec.rb
  54. +1 −1 spec/factory_girl/strategy/attributes_for_spec.rb
  55. +1 −1 spec/factory_girl/strategy/create_spec.rb
  56. +4 −4 spec/factory_girl/strategy/stub_spec.rb
  57. +3 −3 spec/factory_girl/strategy_calculator_spec.rb
  58. +3 −3 spec/factory_girl_spec.rb
  59. +7 −7 spec/support/shared_examples/strategy.rb
View
2 GETTING_STARTED.md
@@ -171,7 +171,7 @@ without having to call them on FactoryGirl directly:
describe User, "#full_name" do
subject { create(:user, first_name: "John", last_name: "Doe") }
- its(:full_name) { should == "John Doe" }
+ its(:full_name) { should eq "John Doe" }
end
```
View
2 features/step_definitions/database_steps.rb
@@ -1,6 +1,6 @@
Then /^I should find the following for the last category:$/ do |table|
table.hashes.first.each do |key, value|
- Category.last.attributes[key].to_s.should == value
+ expect(Category.last.attributes[key].to_s).to eq value
end
end
View
6 spec/acceptance/activesupport_instrumentation_spec.rb
@@ -35,7 +35,7 @@ def subscribed(callback, *args, &block)
FactoryGirl.build(:slow_user)
end
- time_to_execute.should >= 0.1
+ expect(time_to_execute).to be >= 0.1
end
it "builds the correct payload" do
@@ -56,7 +56,7 @@ def subscribed(callback, *args, &block)
FactoryGirl.attributes_for(:slow_user)
end
- tracked_invocations[:slow_user].should == { build: 2, attributes_for: 1 }
- tracked_invocations[:user].should == { build: 5, create: 2 }
+ expect(tracked_invocations[:slow_user]).to eq(build: 2, attributes_for: 1)
+ expect(tracked_invocations[:user]).to eq(build: 5, create: 2)
end
end
View
2 spec/acceptance/aliases_spec.rb
@@ -14,6 +14,6 @@
end
subject { FactoryGirl.create(:user, one: "override") }
- its(:one) { should == "override" }
+ its(:one) { should eq "override" }
its(:two) { should be_nil }
end
View
6 spec/acceptance/attribute_aliases_spec.rb
@@ -29,16 +29,16 @@
subject { FactoryGirl.build(:post, user_id: 1) }
it "doesn't assign both an association and its foreign key" do
- subject.user_id.should == 1
+ expect(subject.user_id).to eq 1
end
end
context "assigning an association by passing factory" do
subject { FactoryGirl.create(:post_with_named_user).user }
it "assigns attributes correctly" do
- subject.name.should == "John Doe"
- subject.age.should == 20
+ expect(subject.name).to eq "John Doe"
+ expect(subject.age).to eq 20
end
end
end
View
16 spec/acceptance/attribute_existing_on_object_spec.rb
@@ -15,9 +15,9 @@
subject { FactoryGirl.build(:website, sleep: -5) }
- its(:system) { should == false }
- its(:link) { should == "http://example.com" }
- its(:sleep) { should == -5 }
+ its(:system) { should eq false }
+ its(:link) { should eq "http://example.com" }
+ its(:sleep) { should eq -5 }
end
describe "assigning overrides that are also private methods on object" do
@@ -42,10 +42,10 @@ def some_funky_method(args)
end
subject { FactoryGirl.build(:website, format: "Great", y: 12345, some_funky_method: "foobar!") }
- its(:format) { should == "Great" }
- its(:y) { should == 12345 }
- its(:more_format) { should == "format: Great" }
- its(:some_funky_method) { should == "foobar!" }
+ its(:format) { should eq "Great" }
+ its(:y) { should eq 12345 }
+ its(:more_format) { should eq "format: Great" }
+ its(:some_funky_method) { should eq "foobar!" }
end
describe "accessing methods from the instance within a dynamic attribute that is also a private method on object" do
@@ -64,5 +64,5 @@ def format
end
subject { FactoryGirl.build(:website) }
- its(:more_format) { should == "format: This is an awesome format" }
+ its(:more_format) { should eq "format: This is an awesome format" }
end
View
20 spec/acceptance/attributes_for_spec.rb
@@ -34,20 +34,20 @@
subject { attributes_for(:post, title: 'overridden title') }
it "assigns an overridden value" do
- subject[:title].should == "overridden title"
+ expect(subject[:title]).to eq "overridden title"
end
it "assigns a default value" do
- subject[:body].should == "default body"
+ expect(subject[:body]).to eq "default body"
end
it "assigns a lazy, dependent attribute" do
- subject[:summary].should == "overridden title"
+ expect(subject[:summary]).to eq "overridden title"
end
it "doesn't assign associations" do
- subject.should_not have_key(:user_id)
- subject.should_not have_key(:user)
+ expect(subject).not_to have_key(:user_id)
+ expect(subject).not_to have_key(:user)
end
end
@@ -64,16 +64,18 @@
it "passes the hash of attributes" do
attributes_for(:company, name: 'thoughtbot') do |attributes|
- attributes[:name].should eq('thoughtbot')
+ expect(attributes[:name]).to eq('thoughtbot')
end
end
it "returns the hash of attributes" do
expected = nil
- attributes_for(:company) do |attributes|
+
+ result = attributes_for(:company) do |attributes|
expected = attributes
"hello!"
- end.should == expected
+ end
+ expect(result).to eq expected
end
end
@@ -91,5 +93,5 @@ def initialize(arg1, arg2); end
end
subject { FactoryGirl.attributes_for(:user) }
- its([:name]) { should == "John Doe" }
+ its([:name]) { should eq "John Doe" }
end
View
14 spec/acceptance/attributes_from_instance_spec.rb
@@ -17,37 +17,37 @@ def age
context "without the attribute being overridden" do
it "returns the correct value from the instance" do
- FactoryGirl.build(:user).age_copy.should == 18
+ expect(FactoryGirl.build(:user).age_copy).to eq 18
end
it "returns nil during attributes_for" do
- FactoryGirl.attributes_for(:user)[:age_copy].should be_nil
+ expect(FactoryGirl.attributes_for(:user)[:age_copy]).to be_nil
end
it "doesn't instantiate a record with attributes_for" do
User.stubs(:new)
FactoryGirl.attributes_for(:user)
- User.should have_received(:new).never
+ expect(User).to have_received(:new).never
end
end
context "with the attribute being overridden" do
it "uses the overridden value" do
- FactoryGirl.build(:user, age_copy: nil).age_copy.should be_nil
+ expect(FactoryGirl.build(:user, age_copy: nil).age_copy).to be_nil
end
it "uses the overridden value during attributes_for" do
- FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy].should == 25
+ expect(FactoryGirl.attributes_for(:user, age_copy: 25)[:age_copy]).to eq 25
end
end
context "with the referenced attribute being overridden" do
it "uses the overridden value" do
- FactoryGirl.build(:user, age: nil).age_copy.should be_nil
+ expect(FactoryGirl.build(:user, age: nil).age_copy).to be_nil
end
it "uses the overridden value during attributes_for" do
- FactoryGirl.attributes_for(:user, age: 25)[:age_copy].should == 25
+ expect(FactoryGirl.attributes_for(:user, age: 25)[:age_copy]).to eq 25
end
end
end
View
12 spec/acceptance/attributes_ordered_spec.rb
@@ -33,19 +33,19 @@
subject { FactoryGirl.build(:child_model) }
it "assigns attributes in the order they're defined with preference to static attributes" do
- subject[:evaluates_first].should == 1
- subject[:evaluates_second].should == 1
- subject[:evaluates_third].should == 1
+ expect(subject[:evaluates_first]).to eq 1
+ expect(subject[:evaluates_second]).to eq 1
+ expect(subject[:evaluates_third]).to eq 1
end
end
context "factory without a parent" do
subject { FactoryGirl.build(:without_parent) }
it "assigns attributes in the order they're defined with preference to static attributes without a parent class" do
- subject[:evaluates_first].should == 1
- subject[:evaluates_second].should == 1
- subject[:evaluates_third].should == 1
+ expect(subject[:evaluates_first]).to eq 1
+ expect(subject[:evaluates_second]).to eq 1
+ expect(subject[:evaluates_third]).to eq 1
end
end
end
View
10 spec/acceptance/build_list_spec.rb
@@ -15,17 +15,17 @@
context "without default attributes" do
subject { FactoryGirl.build_list(:post, 20) }
- its(:length) { should == 20 }
+ its(:length) { should eq 20 }
it "builds (but doesn't save) all the posts" do
subject.each do |record|
- record.should be_new_record
+ expect(record).to be_new_record
end
end
it "uses the default factory values" do
subject.each do |record|
- record.title.should == "Through the Looking Glass"
+ expect(record.title).to eq "Through the Looking Glass"
end
end
end
@@ -35,7 +35,7 @@
it "overrides the default values" do
subject.each do |record|
- record.title.should == "The Hunting of the Snark"
+ expect(record.title).to eq "The Hunting of the Snark"
end
end
end
@@ -49,7 +49,7 @@
it "correctly uses the set value" do
subject.each_with_index do |record, index|
- record.position.should == record.id
+ expect(record.position).to eq record.id
end
end
end
View
23 spec/acceptance/build_spec.rb
@@ -21,13 +21,11 @@
subject { build(:post) }
- it "isn't saved" do
- should be_new_record
- end
+ it { should be_new_record }
it "assigns and saves associations" do
- subject.user.should be_kind_of(User)
- subject.user.should_not be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).not_to be_new_record
end
end
@@ -52,13 +50,11 @@
subject { build(:post) }
- it "isn't saved" do
- should be_new_record
- end
+ it { should be_new_record }
it "assigns but does not save associations" do
- subject.user.should be_kind_of(User)
- subject.user.should be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).to be_new_record
end
end
@@ -75,15 +71,16 @@
it "passes the built instance" do
build(:company, name: 'thoughtbot') do |company|
- company.name.should eq('thoughtbot')
+ expect(company.name).to eq('thoughtbot')
end
end
it "returns the built instance" do
expected = nil
- build(:company) do |company|
+ result = build(:company) do |company|
expected = company
"hello!"
- end.should == expected
+ end
+ expect(result).to eq expected
end
end
View
29 spec/acceptance/build_stubbed_spec.rb
@@ -27,28 +27,28 @@
subject { build_stubbed(:post, title: 'overridden title') }
it "assigns a default attribute" do
- subject.body.should == 'default body'
+ expect(subject.body).to eq 'default body'
end
it "assigns an overridden attribute" do
- subject.title.should == 'overridden title'
+ expect(subject.title).to eq 'overridden title'
end
it "assigns associations" do
- subject.user.should_not be_nil
+ expect(subject.user).not_to be_nil
end
it "has an id" do
- subject.id.should > 0
+ expect(subject.id).to be > 0
end
it "generates unique ids" do
other_stub = build_stubbed(:post)
- subject.id.should_not == other_stub.id
+ expect(subject.id).not_to eq other_stub.id
end
it "isn't a new record" do
- should_not be_new_record
+ expect(subject).not_to be_new_record
end
it "disables connection" do
@@ -89,17 +89,18 @@
it "passes the stub instance" do
build_stubbed(:company, name: 'thoughtbot') do |company|
- company.name.should eq('thoughtbot')
+ expect(company.name).to eq('thoughtbot')
expect { company.save }.to raise_error(RuntimeError)
end
end
it "returns the stub instance" do
expected = nil
- build_stubbed(:company) do |company|
+ result = build_stubbed(:company) do |company|
expected = company
"hello!"
- end.should == expected
+ end
+ expect(result).to eq expected
end
end
@@ -119,25 +120,25 @@
end
it "defaults created_at for objects with created_at" do
- build_stubbed(:thing_with_timestamp).created_at.should == Time.now
+ expect(build_stubbed(:thing_with_timestamp).created_at).to eq Time.now
end
it "defaults created_at for objects with created_at to the correct time with zone" do
original_timezone = ENV['TZ']
ENV['TZ'] = 'UTC'
Time.zone = 'Eastern Time (US & Canada)'
- build_stubbed(:thing_with_timestamp).created_at.zone.should == 'EST'
+ expect(build_stubbed(:thing_with_timestamp).created_at.zone).to eq 'EST'
ENV['TZ'] = original_timezone
end
it "adds created_at to objects who don't have the method" do
- build_stubbed(:thing_without_timestamp).should respond_to(:created_at)
+ expect(build_stubbed(:thing_without_timestamp)).to respond_to(:created_at)
end
it "allows overriding created_at for objects with created_at" do
- build_stubbed(:thing_with_timestamp, created_at: 3.days.ago).created_at.should == 3.days.ago
+ expect(build_stubbed(:thing_with_timestamp, created_at: 3.days.ago).created_at).to eq 3.days.ago
end
it "doesn't allow setting created_at on an object that doesn't define it" do
@@ -155,6 +156,6 @@
end
it 'allows overriding id' do
- FactoryGirl.build_stubbed(:post, id: 12).id.should eq 12
+ expect(FactoryGirl.build_stubbed(:post, id: 12).id).to eq 12
end
end
View
38 spec/acceptance/callbacks_spec.rb
@@ -20,29 +20,29 @@
it "runs the after(:stub) callback when stubbing" do
user = FactoryGirl.build_stubbed(:user_with_callbacks)
- user.first_name.should == 'Stubby'
+ expect(user.first_name).to eq 'Stubby'
end
it "runs the after(:build) callback when building" do
user = FactoryGirl.build(:user_with_callbacks)
- user.first_name.should == 'Buildy'
+ expect(user.first_name).to eq 'Buildy'
end
it "runs both the after(:build) and after(:create) callbacks when creating" do
user = FactoryGirl.create(:user_with_callbacks)
- user.first_name.should == 'Buildy'
- user.last_name.should == 'Createy'
+ expect(user.first_name).to eq 'Buildy'
+ expect(user.last_name).to eq 'Createy'
end
it "runs both the after(:stub) callback on the factory and the inherited after(:stub) callback" do
user = FactoryGirl.build_stubbed(:user_with_inherited_callbacks)
- user.first_name.should == 'Stubby'
- user.last_name.should == 'Double-Stubby'
+ expect(user.first_name).to eq 'Stubby'
+ expect(user.last_name).to eq 'Double-Stubby'
end
it "runs child callback after parent callback" do
user = FactoryGirl.build(:user_with_inherited_callbacks)
- user.first_name.should == 'Child-Buildy'
+ expect(user.first_name).to eq 'Child-Buildy'
end
end
@@ -65,15 +65,15 @@
it "works when the callback has no variables" do
FactoryGirl.build_stubbed(:user)
- FactoryGirl.generate(:sequence_3).should == 2
+ expect(FactoryGirl.generate(:sequence_3)).to eq 2
end
it "works when the callback has one variable" do
- FactoryGirl.build(:user).first_name.should == 1
+ expect(FactoryGirl.build(:user).first_name).to eq 1
end
it "works when the callback has two variables" do
- FactoryGirl.create(:user).last_name.should == 1
+ expect(FactoryGirl.create(:user).last_name).to eq 1
end
end
@@ -135,18 +135,18 @@ def name
end
it "runs a custom before callback when the proper strategy executes" do
- FactoryGirl.build(:user).name.should == "John Doe"
- FactoryGirl.custom_before(:user).name.should == "Overridden First Doe"
+ expect(FactoryGirl.build(:user).name).to eq "John Doe"
+ expect(FactoryGirl.custom_before(:user).name).to eq "Overridden First Doe"
end
it "runs a custom after callback when the proper strategy executes" do
- FactoryGirl.build(:user).name.should == "John Doe"
- FactoryGirl.custom_after(:user).name.should == "John Overridden Last"
+ expect(FactoryGirl.build(:user).name).to eq "John Doe"
+ expect(FactoryGirl.custom_after(:user).name).to eq "John Overridden Last"
end
it "runs a custom callback without prepending before or after when the proper strategy executes" do
- FactoryGirl.build(:user).name.should == "John Doe"
- FactoryGirl.totally_custom(:user).name.should == "Totally Custom"
+ expect(FactoryGirl.build(:user).name).to eq "John Doe"
+ expect(FactoryGirl.totally_custom(:user).name).to eq "Totally Custom"
end
end
@@ -164,14 +164,14 @@ def name
end
it 'binds the callback to creation' do
- FactoryGirl.create(:user, name: 'John Doe').name.should == 'JOHN DOE'
+ expect(FactoryGirl.create(:user, name: 'John Doe').name).to eq 'JOHN DOE'
end
it 'does not bind the callback to building' do
- FactoryGirl.build(:user, name: 'John Doe').name.should == 'John Doe'
+ expect(FactoryGirl.build(:user, name: 'John Doe').name).to eq 'John Doe'
end
it 'binds the callback to stubbing' do
- FactoryGirl.build_stubbed(:user, name: 'John Doe').name.should == 'JOHN DOE'
+ expect(FactoryGirl.build_stubbed(:user, name: 'John Doe').name).to eq 'JOHN DOE'
end
end
View
14 spec/acceptance/create_list_spec.rb
@@ -15,17 +15,17 @@
context "without default attributes" do
subject { FactoryGirl.create_list(:post, 20) }
- its(:length) { should == 20 }
+ its(:length) { should eq 20 }
it "creates all the posts" do
subject.each do |record|
- record.should_not be_new_record
+ expect(record).not_to be_new_record
end
end
it "uses the default factory values" do
subject.each do |record|
- record.title.should == "Through the Looking Glass"
+ expect(record.title).to eq "Through the Looking Glass"
end
end
end
@@ -35,7 +35,7 @@
it "overrides the default values" do
subject.each do |record|
- record.title.should == "The Hunting of the Snark"
+ expect(record.title).to eq "The Hunting of the Snark"
end
end
end
@@ -49,7 +49,7 @@
it "uses the new values" do
subject.each_with_index do |record, index|
- record.position.should == record.id
+ expect(record.position).to eq record.id
end
end
end
@@ -88,10 +88,10 @@
end
it "generates the correct number of posts" do
- FactoryGirl.create(:user_with_posts).posts.length.should == 5
+ expect(FactoryGirl.create(:user_with_posts).posts.length).to eq 5
end
it "allows the number of posts to be modified" do
- FactoryGirl.create(:user_with_posts, posts_count: 2).posts.length.should == 2
+ expect(FactoryGirl.create(:user_with_posts, posts_count: 2).posts.length).to eq 2
end
end
View
21 spec/acceptance/create_spec.rb
@@ -21,13 +21,11 @@
subject { create('post') }
- it "saves" do
- should_not be_new_record
- end
+ it { should_not be_new_record }
it "assigns and saves associations" do
- subject.user.should be_kind_of(User)
- subject.user.should_not be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).not_to be_new_record
end
end
@@ -53,8 +51,8 @@
subject { create(:post) }
it "saves associations (strategy: :build only affects build, not create)" do
- subject.user.should be_kind_of(User)
- subject.user.should_not be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).not_to be_new_record
end
end
@@ -86,7 +84,7 @@ def persisted?
end
it "uses the custom create block instead of save" do
- FactoryGirl.create(:user).should be_persisted
+ expect(FactoryGirl.create(:user)).to be_persisted
end
end
@@ -103,15 +101,16 @@ def persisted?
it "passes the created instance" do
create(:company, name: 'thoughtbot') do |company|
- company.name.should eq('thoughtbot')
+ expect(company.name).to eq('thoughtbot')
end
end
it "returns the created instance" do
expected = nil
- create(:company) do |company|
+ result = create(:company) do |company|
expected = company
"hello!"
- end.should == expected
+ end
+ expect(result).to eq expected
end
end
View
2 spec/acceptance/define_child_before_parent_spec.rb
@@ -16,6 +16,6 @@
end
it "creates admin factories correctly" do
- FactoryGirl.create(:admin).should be_admin
+ expect(FactoryGirl.create(:admin)).to be_admin
end
end
View
9 spec/acceptance/definition_spec.rb
@@ -15,12 +15,7 @@
subject { FactoryGirl.create(:admin) }
- it "uses the correct class name" do
- should be_kind_of(User)
- end
-
- it "uses the correct factory definition" do
- should be_admin
- end
+ it { should be_kind_of(User) }
+ it { should be_admin }
end
View
2 spec/acceptance/definition_without_block_spec.rb
@@ -10,6 +10,6 @@
end
it "registers the user factory" do
- FactoryGirl.factory_by_name(:user).should be_a(FactoryGirl::Factory)
+ expect(FactoryGirl.factory_by_name(:user)).to be_a(FactoryGirl::Factory)
end
end
View
20 spec/acceptance/global_initialize_with_spec.rb
@@ -44,23 +44,23 @@ def initialize(name)
end
it 'handles base initialize_with' do
- FactoryGirl.build(:user).name.should == 'initialize_with'
- FactoryGirl.build(:post).name.should == 'initialize_with'
+ expect(FactoryGirl.build(:user).name).to eq 'initialize_with'
+ expect(FactoryGirl.build(:post).name).to eq 'initialize_with'
end
it 'handles child initialize_with' do
- FactoryGirl.build(:child_user).name.should == 'initialize_with'
- FactoryGirl.build(:child_post).name.should == 'initialize_with'
+ expect(FactoryGirl.build(:child_user).name).to eq 'initialize_with'
+ expect(FactoryGirl.build(:child_post).name).to eq 'initialize_with'
end
it 'handles child initialize_with with trait' do
- FactoryGirl.build(:child_user_with_trait).name.should == 'trait initialize_with'
- FactoryGirl.build(:child_post_with_trait).name.should == 'trait initialize_with'
+ expect(FactoryGirl.build(:child_user_with_trait).name).to eq 'trait initialize_with'
+ expect(FactoryGirl.build(:child_post_with_trait).name).to eq 'trait initialize_with'
end
it 'handles inline trait override' do
- FactoryGirl.build(:child_user, :with_initialize_with).name.should == 'trait initialize_with'
- FactoryGirl.build(:child_post, :with_initialize_with).name.should == 'trait initialize_with'
+ expect(FactoryGirl.build(:child_user, :with_initialize_with).name).to eq 'trait initialize_with'
+ expect(FactoryGirl.build(:child_post, :with_initialize_with).name).to eq 'trait initialize_with'
end
it 'uses initialize_with globally across FactoryGirl.define' do
@@ -76,7 +76,7 @@ def initialize(name)
factory :company
end
- FactoryGirl.build(:company).name.should == 'initialize_with'
- FactoryGirl.build(:company, :with_initialize_with).name.should == 'trait initialize_with'
+ expect(FactoryGirl.build(:company).name).to eq 'initialize_with'
+ expect(FactoryGirl.build(:company, :with_initialize_with).name).to eq 'trait initialize_with'
end
end
View
36 spec/acceptance/global_to_create_spec.rb
@@ -35,23 +35,23 @@
end
it 'handles base to_create' do
- FactoryGirl.create(:user).name.should == 'persisted!'
- FactoryGirl.create(:post).name.should == 'persisted!'
+ expect(FactoryGirl.create(:user).name).to eq 'persisted!'
+ expect(FactoryGirl.create(:post).name).to eq 'persisted!'
end
it 'handles child to_create' do
- FactoryGirl.create(:child_user).name.should == 'persisted!'
- FactoryGirl.create(:child_post).name.should == 'persisted!'
+ expect(FactoryGirl.create(:child_user).name).to eq 'persisted!'
+ expect(FactoryGirl.create(:child_post).name).to eq 'persisted!'
end
it 'handles child to_create with trait' do
- FactoryGirl.create(:child_user_with_trait).name.should == 'override'
- FactoryGirl.create(:child_post_with_trait).name.should == 'override'
+ expect(FactoryGirl.create(:child_user_with_trait).name).to eq 'override'
+ expect(FactoryGirl.create(:child_post_with_trait).name).to eq 'override'
end
it 'handles inline trait override' do
- FactoryGirl.create(:child_user, :override_to_create).name.should == 'override'
- FactoryGirl.create(:child_post, :override_to_create).name.should == 'override'
+ expect(FactoryGirl.create(:child_user, :override_to_create).name).to eq 'override'
+ expect(FactoryGirl.create(:child_post, :override_to_create).name).to eq 'override'
end
it 'uses to_create globally across FactoryGirl.define' do
@@ -61,8 +61,8 @@
factory :company
end
- FactoryGirl.create(:company).name.should == 'persisted!'
- FactoryGirl.create(:company, :override_to_create).name.should == 'override'
+ expect(FactoryGirl.create(:company).name).to eq 'persisted!'
+ expect(FactoryGirl.create(:company, :override_to_create).name).to eq 'override'
end
end
@@ -101,22 +101,22 @@
end
it 'does not persist any record' do
- FactoryGirl.create(:user).should be_new_record
- FactoryGirl.create(:post).should be_new_record
+ expect(FactoryGirl.create(:user)).to be_new_record
+ expect(FactoryGirl.create(:post)).to be_new_record
end
it 'does not persist child records' do
- FactoryGirl.create(:child_user).should be_new_record
- FactoryGirl.create(:child_post).should be_new_record
+ expect(FactoryGirl.create(:child_user)).to be_new_record
+ expect(FactoryGirl.create(:child_post)).to be_new_record
end
it 'honors overridden to_create' do
- FactoryGirl.create(:child_user_with_trait).name.should == 'override'
- FactoryGirl.create(:child_post_with_trait).name.should == 'override'
+ expect(FactoryGirl.create(:child_user_with_trait).name).to eq 'override'
+ expect(FactoryGirl.create(:child_post_with_trait).name).to eq 'override'
end
it 'honors inline trait to_create' do
- FactoryGirl.create(:child_user, :override_to_create).name.should == 'override'
- FactoryGirl.create(:child_post, :override_to_create).name.should == 'override'
+ expect(FactoryGirl.create(:child_user, :override_to_create).name).to eq 'override'
+ expect(FactoryGirl.create(:child_post, :override_to_create).name).to eq 'override'
end
end
View
26 spec/acceptance/initialize_with_spec.rb
@@ -18,8 +18,8 @@ def self.construct(name, age)
end
subject { build(:user) }
- its(:name) { should == "John Doe" }
- its(:age) { should == 21 }
+ its(:name) { should eq "John Doe" }
+ its(:age) { should eq 21 }
end
describe "initialize_with with FG attributes that are ignored" do
@@ -44,7 +44,7 @@ def self.construct(name)
end
subject { build(:user) }
- its(:name) { should == "Handsome Chap from .construct" }
+ its(:name) { should eq "Handsome Chap from .construct" }
end
describe "initialize_with non-ORM-backed objects" do
@@ -74,11 +74,11 @@ def initialize(name, data)
end
it "allows for overrides" do
- build(:report_generator, name: "Overridden").name.should == "Overridden"
+ expect(build(:report_generator, name: "Overridden").name).to eq "Overridden"
end
it "generates random data" do
- build(:report_generator).data.length.should == 5
+ expect(build(:report_generator).data.length).to eq 5
end
end
@@ -114,11 +114,11 @@ def initialize(name)
end
it "uses the parent's constructor when the child factory doesn't assign it" do
- FactoryGirl.build(:sub_awesome).name.should == "Sub"
+ expect(FactoryGirl.build(:sub_awesome).name).to eq "Sub"
end
it "allows child factories to override initialize_with" do
- FactoryGirl.build(:super_awesome).name.should == "Super"
+ expect(FactoryGirl.build(:super_awesome).name).to eq "Super"
end
end
@@ -144,7 +144,7 @@ def initialize(name)
end
it "instantiates the correct object" do
- FactoryGirl.build(:awesome, name: "Awesome name").name.should == "Awesome name"
+ expect(FactoryGirl.build(:awesome, name: "Awesome name").name).to eq "Awesome name"
end
end
@@ -174,8 +174,8 @@ def initialize(name)
it "instantiates the correct object" do
built_user = FactoryGirl.build(:user)
- built_user.name.should == "person1"
- built_user.email.should == "person1@example.com"
+ expect(built_user.name).to eq "person1"
+ expect(built_user.email).to eq "person1@example.com"
end
end
@@ -210,8 +210,8 @@ def initialize(attributes = {})
it "assigns attributes correctly" do
user_with_attributes = FactoryGirl.build(:user)
- user_with_attributes.email.should == "person1@example.com"
- user_with_attributes.name.should == "person1"
- user_with_attributes.ignored.should be_nil
+ expect(user_with_attributes.email).to eq "person1@example.com"
+ expect(user_with_attributes.name).to eq "person1"
+ expect(user_with_attributes.ignored).to be_nil
end
end
View
4 spec/acceptance/keyed_by_class_spec.rb
@@ -16,7 +16,7 @@
it 'allows interaction based on class name' do
user = FactoryGirl.create User, email: 'person@example.com'
- user.email.should == 'person@example.com'
- user.name.should == 'John Doe'
+ expect(user.email).to eq 'person@example.com'
+ expect(user.name).to eq 'John Doe'
end
end
View
42 spec/acceptance/modify_factories_spec.rb
@@ -33,8 +33,8 @@
end
subject { create(:user) }
- its(:name) { should == "Great User" }
- its(:login) { should == "GREAT USER" }
+ its(:name) { should eq "Great User" }
+ its(:login) { should eq "GREAT USER" }
it "doesn't allow the factory to be subsequently defined" do
expect do
@@ -49,7 +49,7 @@
end
end
- create(:user).name.should == "Overridden again!"
+ expect(create(:user).name).to eq "Overridden again!"
end
end
@@ -68,7 +68,7 @@
subject { create(:user) }
- its(:name) { should == "great user" }
+ its(:name) { should eq "great user" }
its(:login) { should be_nil }
end
@@ -90,9 +90,9 @@
subject { create(:user) }
- its(:name) { should == "Johnny Rockstar!!!" }
- its(:email) { should == "Johnny Rockstar!!!@example.com" }
- its(:login) { should == "JOHNNY ROCKSTAR!!!" }
+ its(:name) { should eq "Johnny Rockstar!!!" }
+ its(:email) { should eq "Johnny Rockstar!!!@example.com" }
+ its(:login) { should eq "JOHNNY ROCKSTAR!!!" }
end
context "redefining attributes" do
@@ -109,47 +109,47 @@
context "without overrides" do
subject { create(:user) }
- its(:name) { should == "Great User" }
- its(:email) { should == "Great User-modified@example.com" }
+ its(:name) { should eq "Great User" }
+ its(:email) { should eq "Great User-modified@example.com" }
end
context "overriding dynamic attributes" do
subject { create(:user, email: "perfect@example.com") }
- its(:name) { should == "Great User" }
- its(:email) { should == "perfect@example.com" }
+ its(:name) { should eq "Great User" }
+ its(:email) { should eq "perfect@example.com" }
end
context "overriding static attributes" do
subject { create(:user, name: "wonderful") }
- its(:name) { should == "wonderful" }
- its(:email) { should == "wonderful-modified@example.com" }
+ its(:name) { should eq "wonderful" }
+ its(:email) { should eq "wonderful-modified@example.com" }
end
end
context "creating admin" do
context "without overrides" do
subject { create(:admin) }
- its(:name) { should == "Great User" }
- its(:email) { should == "Great User-modified@example.com" }
+ its(:name) { should eq "Great User" }
+ its(:email) { should eq "Great User-modified@example.com" }
its(:admin) { should be_true }
end
context "overriding dynamic attributes" do
subject { create(:admin, email: "perfect@example.com") }
- its(:name) { should == "Great User" }
- its(:email) { should == "perfect@example.com" }
+ its(:name) { should eq "Great User" }
+ its(:email) { should eq "perfect@example.com" }
its(:admin) { should be_true }
end
context "overriding static attributes" do
subject { create(:admin, name: "wonderful") }
- its(:name) { should == "wonderful" }
- its(:email) { should == "wonderful-modified@example.com" }
+ its(:name) { should eq "wonderful" }
+ its(:email) { should eq "wonderful-modified@example.com" }
its(:admin) { should be_true }
end
end
@@ -161,7 +161,7 @@
admin false
end
end
- create(:admin).should be_admin
+ expect(create(:admin)).to be_admin
end
it "allows for overriding child classes" do
@@ -171,7 +171,7 @@
end
end
- create(:admin).should_not be_admin
+ expect(create(:admin)).not_to be_admin
end
it "raises an exception if the factory was not defined before" do
View
14 spec/acceptance/modify_inherited_spec.rb
@@ -29,13 +29,13 @@
end
it "returns the correct value for overridden attributes from traits" do
- FactoryGirl.build(:male_user).gender.should == "Male"
+ expect(FactoryGirl.build(:male_user).gender).to eq "Male"
end
it "returns the correct value for overridden attributes from traits defining multiple attributes" do
- FactoryGirl.build(:female_user).gender.should == "Female"
- FactoryGirl.build(:female_user).age.should == 25
- FactoryGirl.build(:female_user).admin.should == true
+ expect(FactoryGirl.build(:female_user).gender).to eq "Female"
+ expect(FactoryGirl.build(:female_user).age).to eq 25
+ expect(FactoryGirl.build(:female_user).admin).to eq true
end
it "allows modification of attributes created via traits" do
@@ -45,8 +45,8 @@
end
end
- FactoryGirl.build(:male_user).gender.should == "Male"
- FactoryGirl.build(:male_user).age.should == 20
- FactoryGirl.build(:male_user).admin.should == true
+ expect(FactoryGirl.build(:male_user).gender).to eq "Male"
+ expect(FactoryGirl.build(:male_user).age).to eq 20
+ expect(FactoryGirl.build(:male_user).admin).to eq true
end
end
View
4 spec/acceptance/nested_attributes_spec.rb
@@ -23,10 +23,10 @@
end
it "assigns the correct amount of comments" do
- FactoryGirl.create(:post).comments.count.should == 2
+ expect(FactoryGirl.create(:post).comments.count).to eq 2
end
it "assigns the correct amount of comments when overridden" do
- FactoryGirl.create(:post, :comments_attributes => [FactoryGirl.attributes_for(:comment)]).comments.count.should == 1
+ expect(FactoryGirl.create(:post, :comments_attributes => [FactoryGirl.attributes_for(:comment)]).comments.count).to eq 1
end
end
View
2 spec/acceptance/overrides_spec.rb
@@ -46,7 +46,7 @@ def secure=(value)
context "with an admin posting" do
subject { FactoryGirl.create(:post, admin_post_attributes) }
- its(:secure) { should == false }
+ its(:secure) { should eq false }
end
context "with a non-admin posting" do
View
18 spec/acceptance/parent_spec.rb
@@ -34,34 +34,34 @@
describe "the parent class" do
subject { FactoryGirl.create(:user) }
it { should_not be_admin }
- its(:email) { should == "john@example.com" }
+ its(:email) { should eq "john@example.com" }
end
describe "the child class redefining parent's static method used by a dynamic method" do
subject { FactoryGirl.create(:admin) }
it { should be_kind_of(User) }
it { should be_admin }
- its(:name) { should == "admin" }
- its(:email) { should == "admin@example.com" }
- its(:upper_email) { should == "ADMIN@EXAMPLE.COM"}
+ its(:name) { should eq "admin" }
+ its(:email) { should eq "admin@example.com" }
+ its(:upper_email) { should eq "ADMIN@EXAMPLE.COM"}
end
describe "the child class redefining parent's dynamic method" do
subject { FactoryGirl.create(:guest) }
it { should_not be_admin }
- its(:name) { should == "John" }
+ its(:name) { should eq "John" }
its(:email) { should eql "John-guest@example.com" }
- its(:login) { should == "John-guest@example.com" }
+ its(:login) { should eq "John-guest@example.com" }
end
describe "the child class redefining parent's dynamic attribute with static attribute" do
subject { FactoryGirl.create(:no_email) }
- its(:email) { should == "" }
+ its(:email) { should eq "" }
end
describe "the child class redefining parent's static attribute with dynamic attribute" do
subject { FactoryGirl.create(:bill) }
- its(:name) { should == "Bill" }
+ its(:name) { should eq "Bill" }
end
end
@@ -85,6 +85,6 @@
end
it "honors :parent over the factory block nesting" do
- FactoryGirl.build(:uppercase_male_user).name.should == "JOHN DOE"
+ expect(FactoryGirl.build(:uppercase_male_user).name).to eq "JOHN DOE"
end
end
View
18 spec/acceptance/register_strategies_spec.rb
@@ -30,24 +30,24 @@ def result(evaluation)
end
it "allows overriding default strategies" do
- FactoryGirl.build(:named_object).name.should == "Great"
+ expect(FactoryGirl.build(:named_object).name).to eq "Great"
FactoryGirl.register_strategy(:build, custom_strategy)
- FactoryGirl.build(:named_object).name.should == "Custom strategy"
+ expect(FactoryGirl.build(:named_object).name).to eq "Custom strategy"
end
it "allows adding additional strategies" do
FactoryGirl.register_strategy(:insert, custom_strategy)
- FactoryGirl.build(:named_object).name.should == "Great"
- FactoryGirl.insert(:named_object).name.should == "Custom strategy"
+ expect(FactoryGirl.build(:named_object).name).to eq "Great"
+ expect(FactoryGirl.insert(:named_object).name).to eq "Custom strategy"
end
it "allows using the *_list method to build a list using a custom strategy" do
FactoryGirl.register_strategy(:insert, custom_strategy)
inserted_items = FactoryGirl.insert_list(:named_object, 2)
- inserted_items.length.should == 2
- inserted_items.map(&:name).should == ["Custom strategy", "Custom strategy"]
+ expect(inserted_items.length).to eq 2
+ expect(inserted_items.map(&:name)).to eq ["Custom strategy", "Custom strategy"]
end
end
@@ -67,7 +67,7 @@ def result(evaluation)
it "allows adding additional strategies" do
FactoryGirl.register_strategy(:insert, custom_strategy)
- insert(:named_object).name.should == "Custom strategy"
+ expect(insert(:named_object).name).to eq "Custom strategy"
end
end
@@ -95,7 +95,7 @@ def result(evaluation)
it "uses the overridden create strategy to create the association" do
FactoryGirl.register_strategy(:create, custom_strategy)
post = FactoryGirl.build(:post)
- post.user.name.should == "Custom strategy"
+ expect(post.user.name).to eq "Custom strategy"
end
end
@@ -123,6 +123,6 @@ def result(evaluation)
it "uses the overridden create strategy to create the association" do
FactoryGirl.register_strategy(:insert, custom_strategy)
post = FactoryGirl.build(:post)
- post.user.name.should == "Custom strategy"
+ expect(post.user.name).to eq "Custom strategy"
end
end
View
8 spec/acceptance/sequence_context_spec.rb
@@ -18,7 +18,7 @@ def awesome
end
end
- FactoryGirl.build(:sequence_with_sprintf).id.should == 'foo1'
+ expect(FactoryGirl.build(:sequence_with_sprintf).id).to eq 'foo1'
end
it 'invokes the correct method on the instance' do
@@ -28,7 +28,7 @@ def awesome
end
end
- FactoryGirl.build(:sequence_with_public_method).id.should == 'aw yeah'
+ expect(FactoryGirl.build(:sequence_with_public_method).id).to eq 'aw yeah'
end
it 'invokes a method with no arguments on the instance' do
@@ -38,7 +38,7 @@ def awesome
end
end
- FactoryGirl.build(:sequence_with_frozen).id.should be_false
+ expect(FactoryGirl.build(:sequence_with_frozen).id).to be_false
end
it 'allows direct reference of a method in a sequence' do
@@ -47,6 +47,6 @@ def awesome
sequence(:id) {|n| "#{awesome}#{n}" }
end
end
- FactoryGirl.build(:sequence_referencing_attribute_directly).id.should == 'aw yeah1'
+ expect(FactoryGirl.build(:sequence_referencing_attribute_directly).id).to eq 'aw yeah1'
end
end
View
24 spec/acceptance/sequence_spec.rb
@@ -13,9 +13,9 @@
first_value = generate(:email)
another_value = generate(:email)
- first_value.should =~ /^somebody\d+@example\.com$/
- another_value.should =~ /^somebody\d+@example\.com$/
- first_value.should_not == another_value
+ expect(first_value).to match /^somebody\d+@example\.com$/
+ expect(another_value).to match /^somebody\d+@example\.com$/
+ expect(first_value).not_to eq another_value
end
it "generates sequential numbers if no block is given" do
@@ -26,9 +26,9 @@
first_value = generate(:order)
another_value = generate(:order)
- first_value.should == 1
- another_value.should == 2
- first_value.should_not == another_value
+ expect(first_value).to eq 1
+ expect(another_value).to eq 2
+ expect(first_value).not_to eq another_value
end
it "generates aliases for the sequence that reference the same block" do
@@ -40,9 +40,9 @@
second_value = generate(:count)
third_value = generate(:length)
- first_value.should == "called-1"
- second_value.should == "called-2"
- third_value.should == "called-3"
+ expect(first_value).to eq "called-1"
+ expect(second_value).to eq "called-2"
+ expect(third_value).to eq "called-3"
end
it "generates aliases for the sequence that reference the same block and retains value" do
@@ -54,8 +54,8 @@
second_value = generate(:count)
third_value = generate(:length)
- first_value.should == "called-a"
- second_value.should == "called-b"
- third_value.should == "called-c"
+ expect(first_value).to eq "called-a"
+ expect(second_value).to eq "called-b"
+ expect(third_value).to eq "called-c"
end
end
View
2 spec/acceptance/skip_create_spec.rb
@@ -14,6 +14,6 @@
end
it "doesn't execute anything when creating the instance" do
- FactoryGirl.create(:user).should_not be_persisted
+ expect(FactoryGirl.create(:user)).not_to be_persisted
end
end
View
8 spec/acceptance/stub_spec.rb
@@ -26,8 +26,8 @@
end
it "assigns associations and acts as if it is saved" do
- subject.user.should be_kind_of(User)
- subject.user.should_not be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).not_to be_new_record
end
end
@@ -56,7 +56,7 @@
end
it "assigns associations and acts as if it is saved" do
- subject.user.should be_kind_of(User)
- subject.user.should_not be_new_record
+ expect(subject.user).to be_kind_of(User)
+ expect(subject.user).not_to be_new_record
end
end
View
10 spec/acceptance/syntax_methods_within_dynamic_attributes_spec.rb
@@ -26,16 +26,16 @@ def generate
end
it "can access syntax methods from dynamic attributes" do
- FactoryGirl.build(:user).email.should == "person-1@example.com"
- FactoryGirl.attributes_for(:user)[:email].should == "person-2@example.com"
+ expect(FactoryGirl.build(:user).email).to eq "person-1@example.com"
+ expect(FactoryGirl.attributes_for(:user)[:email]).to eq "person-2@example.com"
end
it "can access syntax methods from dynamic attributes" do
- FactoryGirl.build(:post).user.should be_instance_of(User)
+ expect(FactoryGirl.build(:post).user).to be_instance_of(User)
end
it "can access methods already existing on the class" do
- FactoryGirl.build(:post).title.should == "generate result"
- FactoryGirl.attributes_for(:post)[:title].should be_nil
+ expect(FactoryGirl.build(:post).title).to eq "generate result"
+ expect(FactoryGirl.attributes_for(:post)[:title]).to be_nil
end
end
View
168 spec/acceptance/traits_spec.rb
@@ -84,87 +84,87 @@
context "the parent class" do
subject { FactoryGirl.create(:user) }
- its(:name) { should == "John" }
+ its(:name) { should eq "John" }
its(:gender) { should be_nil }
it { should_not be_admin }
end
context "the child class with one trait" do
subject { FactoryGirl.create(:admin) }
- its(:name) { should == "John" }
+ its(:name) { should eq "John" }
its(:gender) { should be_nil }
it { should be_admin }
end
context "the other child class with one trait" do
subject { FactoryGirl.create(:female) }
- its(:name) { should == "Jane" }
- its(:gender) { should == "Female" }
+ its(:name) { should eq "Jane" }
+ its(:gender) { should eq "Female" }
it { should_not be_admin }
end
context "the child with multiple traits" do
subject { FactoryGirl.create(:female_admin) }
- its(:name) { should == "Jane" }
- its(:gender) { should == "Female" }
+ its(:name) { should eq "Jane" }
+ its(:gender) { should eq "Female" }
it { should be_admin }
end
context "the child with multiple traits and overridden attributes" do
subject { FactoryGirl.create(:female_admin, name: "Jill", gender: nil) }
- its(:name) { should == "Jill" }
+ its(:name) { should eq "Jill" }
its(:gender) { should be_nil }
it { should be_admin }
end
context "the child with multiple traits who override the same attribute" do
context "when the male assigns name after female" do
subject { FactoryGirl.create(:male_after_female_admin) }
- its(:name) { should == "Joe" }
- its(:gender) { should == "Male" }
+ its(:name) { should eq "Joe" }
+ its(:gender) { should eq "Male" }
it { should be_admin }
end
context "when the female assigns name after male" do
subject { FactoryGirl.create(:female_after_male_admin) }
- its(:name) { should == "Jane" }
- its(:gender) { should == "Female" }
+ its(:name) { should eq "Jane" }
+ its(:gender) { should eq "Female" }
it { should be_admin }
end
end
context "child class with scoped trait and inherited trait" do
subject { FactoryGirl.create(:female_admin_judy) }
- its(:name) { should == "Judy" }
- its(:gender) { should == "Female" }
+ its(:name) { should eq "Judy" }
+ its(:gender) { should eq "Female" }
it { should be_admin }
end
context "factory using global trait" do
subject { FactoryGirl.create(:user_with_email) }
- its(:name) { should == "Bill" }
- its(:email) { should == "Bill@example.com"}
+ its(:name) { should eq "Bill" }
+ its(:email) { should eq "Bill@example.com"}
end
context "factory created with alternate syntax for specifying trait" do
subject { FactoryGirl.create(:male_user) }
- its(:gender) { should == "Male" }
+ its(:gender) { should eq "Male" }
end
context "factory created with alternate syntax where trait name and attribute are the same" do
subject { FactoryGirl.create(:great_user) }
- its(:great) { should == "GREAT!!!" }
+ its(:great) { should eq "GREAT!!!" }
end
context "factory created with alternate syntax where trait name and attribute are the same and attribute is overridden" do
subject { FactoryGirl.create(:great_user, great: "SORT OF!!!") }
- its(:great) { should == "SORT OF!!!" }
+ its(:great) { should eq "SORT OF!!!" }
end
context "child factory created where trait attributes are inherited" do
subject { FactoryGirl.create(:child_male_user) }
- its(:gender) { should == "Male" }
- its(:date_of_birth) { should == Date.parse("1/1/2000") }
+ its(:gender) { should eq "Male" }
+ its(:date_of_birth) { should eq Date.parse("1/1/2000") }
end
context "factory outside of scope" do
@@ -174,7 +174,7 @@
context "child factory using grandparents' trait" do
subject { FactoryGirl.create(:female_great_user) }
- its(:great) { should == "GREAT!!!" }
+ its(:great) { should eq "GREAT!!!" }
end
end
@@ -206,16 +206,16 @@
context "when the factory has a trait passed via arguments" do
subject { FactoryGirl.create(:caps_user) }
- its(:name) { should == "JOHN" }
+ its(:name) { should eq "JOHN" }
end
context "when the factory has an implicit trait" do
subject { FactoryGirl.create(:caps_user_implicit_trait) }
- its(:name) { should == "JOHN" }
+ its(:name) { should eq "JOHN" }
end
it "executes callbacks in the order assigned" do
- FactoryGirl.create(:awesome_user).name.should == "awesome"
+ expect(FactoryGirl.create(:awesome_user).name).to eq "awesome"
end
end
@@ -242,58 +242,58 @@
subject { FactoryGirl.create(:user, :admin, :great, name: "Joe") }
its(:admin) { should be_true }
- its(:name) { should == "JOE" }
+ its(:name) { should eq "JOE" }
it "doesn't modify the user factory" do
subject
- FactoryGirl.create(:user).should_not be_admin
- FactoryGirl.create(:user).name.should == "John"
+ expect(FactoryGirl.create(:user)).not_to be_admin
+ expect(FactoryGirl.create(:user).name).to eq "John"
end
end
context "adding traits in build" do
subject { FactoryGirl.build(:user, :admin, :great, name: "Joe") }
its(:admin) { should be_true }
- its(:name) { should == "Joe" }
+ its(:name) { should eq "Joe" }
end
context "adding traits in attributes_for" do
subject { FactoryGirl.attributes_for(:user, :admin, :great) }
its([:admin]) { should be_true }
- its([:name]) { should == "John" }
+ its([:name]) { should eq "John" }
end
context "adding traits in build_stubbed" do
subject { FactoryGirl.build_stubbed(:user, :admin, :great, name: "Jack") }
its(:admin) { should be_true }
- its(:name) { should == "Jack" }
+ its(:name) { should eq "Jack" }
end
context "adding traits in create_list" do
subject { FactoryGirl.create_list(:user, 2, :admin, :great, name: "Joe") }
- its(:length) { should == 2 }
+ its(:length) { should eq 2 }
it "creates all the records" do
subject.each do |record|
- record.admin.should be_true
- record.name.should == "JOE"
+ expect(record.admin).to be_true
+ expect(record.name).to eq "JOE"
end
end
end
context "adding traits in build_list" do
subject { FactoryGirl.build_list(:user, 2, :admin, :great, name: "Joe") }
- its(:length) { should == 2 }
+ its(:length) { should eq 2 }
it "builds all the records" do
subject.each do |record|
- record.admin.should be_true
- record.name.should == "Joe"
+ expect(record.admin).to be_true
+ expect(record.name).to eq "Joe"
end
end
end
@@ -317,9 +317,9 @@
end
subject { FactoryGirl.build(:user) }
- its(:name) { should == "John" }
- its(:email) { should == "John@example.com" }
- its(:combined) { should == "John <John@example.com>" }
+ its(:name) { should eq "John" }
+ its(:email) { should eq "John@example.com" }
+ its(:combined) { should eq "John <John@example.com>" }
end
describe "applying inline traits" do
@@ -342,9 +342,9 @@
end
it "applies traits only to the instance generated for that call" do
- FactoryGirl.create(:user, :with_post).posts.should_not be_empty
- FactoryGirl.create(:user).posts.should be_empty
- FactoryGirl.create(:user, :with_post).posts.should_not be_empty
+ expect(FactoryGirl.create(:user, :with_post).posts).not_to be_empty
+ expect(FactoryGirl.create(:user).posts).to be_empty
+ expect(FactoryGirl.create(:user, :with_post).posts).not_to be_empty
end
end
@@ -368,31 +368,31 @@
end
it "returns the default status" do
- FactoryGirl.build(:user).status.should == "pending"
+ expect(FactoryGirl.build(:user).status).to eq "pending"
end
it "prefers inline trait attributes over default attributes" do
- FactoryGirl.build(:user, :accepted).status.should == "accepted"
+ expect(FactoryGirl.build(:user, :accepted).status).to eq "accepted"
end
it "prefers traits on a factory over default attributes" do
- FactoryGirl.build(:declined_user).status.should == "declined"
+ expect(FactoryGirl.build(:declined_user).status).to eq "declined"
end
it "prefers inline trait attributes over traits on a factory" do
- FactoryGirl.build(:declined_user, :accepted).status.should == "accepted"
+ expect(FactoryGirl.build(:declined_user, :accepted).status).to eq "accepted"
end
it "prefers attributes on factories over attributes from non-inline traits" do
- FactoryGirl.build(:extended_declined_user).status.should == "extended_declined"
+ expect(FactoryGirl.build(:extended_declined_user).status).to eq "extended_declined"
end
it "prefers inline traits over attributes on factories" do
- FactoryGirl.build(:extended_declined_user, :accepted).status.should == "accepted"
+ expect(FactoryGirl.build(:extended_declined_user, :accepted).status).to eq "accepted"
end
it "prefers overridden attributes over attributes from traits, inline traits, or attributes on factories" do
- FactoryGirl.build(:extended_declined_user, :accepted, status: "completely overridden").status.should == "completely overridden"
+ expect(FactoryGirl.build(:extended_declined_user, :accepted, status: "completely overridden").status).to eq "completely overridden"
end
end
@@ -414,9 +414,9 @@
it "can honor traits on the very first call" do
user = FactoryGirl.build(:female_user, :admin, age: 30)
- user.gender.should == 'female'
- user.age.should == 30
- user.role.should == 'admin'
+ expect(user.gender).to eq 'female'
+ expect(user.age).to eq 30
+ expect(user.role).to eq 'admin'
end
end
@@ -453,27 +453,27 @@
end
it "can apply to_create from traits" do
- FactoryGirl.create(:user, :with_to_create).name.should == "to_create"
+ expect(FactoryGirl.create(:user, :with_to_create).name).to eq "to_create"
end
it "can apply to_create from the definition" do
- FactoryGirl.create(:sub_user).name.should == "sub"
- FactoryGirl.create(:child_user).name.should == "sub"
+ expect(FactoryGirl.create(:sub_user).name).to eq "sub"
+ expect(FactoryGirl.create(:child_user).name).to eq "sub"
end
it "gives additional traits higher priority than to_create from the definition" do
- FactoryGirl.create(:sub_user, :with_to_create).name.should == "to_create"
- FactoryGirl.create(:child_user, :with_to_create).name.should == "to_create"
+ expect(FactoryGirl.create(:sub_user, :with_to_create).name).to eq "to_create"
+ expect(FactoryGirl.create(:child_user, :with_to_create).name).to eq "to_create"
end
it "gives base traits normal priority" do
- FactoryGirl.create(:sub_user_with_trait).name.should == "to_create"
- FactoryGirl.create(:child_user_with_trait).name.should == "to_create"
+ expect(FactoryGirl.create(:sub_user_with_trait).name).to eq "to_create"
+ expect(FactoryGirl.create(:child_user_with_trait).name).to eq "to_create"
end
it "gives base traits lower priority than overrides" do
- FactoryGirl.create(:sub_user_with_trait_and_override).name.should == "sub with trait and override"
- FactoryGirl.create(:child_user_with_trait_and_override).name.should == "sub with trait and override"
+ expect(FactoryGirl.create(:sub_user_with_trait_and_override).name).to eq "sub with trait and override"
+ expect(FactoryGirl.create(:child_user_with_trait_and_override).name).to eq "sub with trait and override"
end
it "gives additional traits higher priority than base traits and factory definition" do
@@ -483,8 +483,8 @@
end
end
- FactoryGirl.create(:sub_user_with_trait_and_override, :overridden).name.should == "completely overridden"
- FactoryGirl.create(:child_user_with_trait_and_override, :overridden).name.should == "completely overridden"
+ expect(FactoryGirl.create(:sub_user_with_trait_and_override, :overridden).name).to eq "completely overridden"
+ expect(FactoryGirl.create(:child_user_with_trait_and_override, :overridden).name).to eq "completely overridden"
end
end
@@ -527,27 +527,27 @@ def initialize(name)
end
it "can apply initialize_with from traits" do
- FactoryGirl.build(:user, :with_initialize_with).name.should == "initialize_with"
+ expect(FactoryGirl.build(:user, :with_initialize_with).name).to eq "initialize_with"
end
it "can apply initialize_with from the definition" do
- FactoryGirl.build(:sub_user).name.should == "sub"
- FactoryGirl.build(:child_user).name.should == "sub"
+ expect(FactoryGirl.build(:sub_user).name).to eq "sub"
+ expect(FactoryGirl.build(:child_user).name).to eq "sub"
end
it "gives additional traits higher priority than initialize_with from the definition" do
- FactoryGirl.build(:sub_user, :with_initialize_with).name.should == "initialize_with"
- FactoryGirl.build(:child_user, :with_initialize_with).name.should == "initialize_with"
+ expect(FactoryGirl.build(:sub_user, :with_initialize_with).name).to eq "initialize_with"
+ expect(FactoryGirl.build(:child_user, :with_initialize_with).name).to eq "initialize_with"
end
it "gives base traits normal priority" do
- FactoryGirl.build(:sub_user_with_trait).name.should == "initialize_with"
- FactoryGirl.build(:child_user_with_trait).name.should == "initialize_with"
+ expect(FactoryGirl.build(:sub_user_with_trait).name).to eq "initialize_with"
+ expect(FactoryGirl.build(:child_user_with_trait).name).to eq "initialize_with"
end
it "gives base traits lower priority than overrides" do
- FactoryGirl.build(:sub_user_with_trait_and_override).name.should == "sub with trait and override"
- FactoryGirl.build(:child_user_with_trait_and_override).name.should == "sub with trait and override"
+ expect(FactoryGirl.build(:sub_user_with_trait_and_override).name).to eq "sub with trait and override"
+ expect(FactoryGirl.build(:child_user_with_trait_and_override).name).to eq "sub with trait and override"
end
it "gives additional traits higher priority than base traits and factory definition" do
@@ -557,8 +557,8 @@ def initialize(name)
end
end
- FactoryGirl.build(:sub_user_with_trait_and_override, :overridden).name.should == "completely overridden"
- FactoryGirl.build(:child_user_with_trait_and_override, :overridden).name.should == "completely overridden"
+ expect(FactoryGirl.build(:sub_user_with_trait_and_override, :overridden).name).to eq "completely overridden"
+ expect(FactoryGirl.build(:child_user_with_trait_and_override, :overridden).name).to eq "completely overridden"
end
end
@@ -577,9 +577,9 @@ def initialize(name)
shared_examples_for "assigning data from traits" do
it "assigns the correct values" do
user = FactoryGirl.create(:user, :female_admin)
- user.gender.should == "FEMALE"
- user.role.should == "ADMIN"
- user.name.should == "Jane Doe"
+ expect(user.gender).to eq "FEMALE"
+ expect(user.role).to eq "ADMIN"
+ expect(user.name).to eq "Jane Doe"
end
end
@@ -664,7 +664,7 @@ def initialize(name)
end
it "only runs the callback once" do
- FactoryGirl.build(:user_with_trait_with_callback).value.should == 1
+ expect(FactoryGirl.build(:user_with_trait_with_callback).value).to eq 1
end
end
@@ -709,19 +709,19 @@ def initialize(name)
it "allows assigning traits for the factory of an association" do
author = FactoryGirl.create(:post).author
- author.should be_admin
- author.name.should == 'John Doe'
+ expect(author).to be_admin
+ expect(author.name).to eq 'John Doe'
end