Skip to content

Instantly share code, notes, and snippets.

@tpendragon
Created October 2, 2013 15:07
Show Gist options
  • Save tpendragon/6795246 to your computer and use it in GitHub Desktop.
Save tpendragon/6795246 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe Car do
let(:manufacturer) { FactoryGirl.create(:manufacturer)}
let(:car) { FactoryGirl.create(:car, manufacturer: manufacturer)}
it "basic_articles with no extras required" do
basic_article = FactoryGirl.create(:basic_article, requires_extra: false)
expect(manufacturer.selectable_cars.count).to eq(1)
end
it "basic_articles with extras required" do
basic_article = FactoryGirl.create(:basic_article, requires_extra: true)
expect(manufacturer.selectable_cars.count).to eq(0)
end
it "basic_articles with extras with and without extras" do
basic_article = FactoryGirl.create(:basic_article, requires_extra: false)
basic_article_2 = FactoryGirl.create(:basic_article)
article = FactoryGirl.create(:article)
extra = FactoryGirl.create(:extra, cars: [car], basic_articles: [basic_article_2], articles: [article])
expect(manufacturer.selectable_cars.count).to eq(2)
end
end
Running tests with args ["--drb", "-f", "progress", "-r", "/usr/local/opt/rbenv/versions/2.0.0-rc2/lib/ruby/gems/2.0.0/gems/guard-rspec-3.0.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec"]...
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
.FF......
Failures:
1) Car basic_articles with extras with and without extras
Failure/Error: expect(manufacturer.selectable_cars.count).to eq(2)
expected: 2
got: 1
(compared using ==)
# ./spec/models/car_spec.rb:22:in `block (2 levels) in <top (required)>'
2) Car basic_articles with extras required
Failure/Error: expect(manufacturer.selectable_cars.count).to eq(0)
expected: 0
got: 1
(compared using ==)
# ./spec/models/car_spec.rb:14:in `block (2 levels) in <top (required)>'
Finished in 1.97 seconds
9 examples, 2 failures
Failed examples:
rspec ./spec/models/car_spec.rb:17 # Car basic_articles with extras with and without extras
rspec ./spec/models/car_spec.rb:12 # Car basic_articles with extras required
Randomized with seed 23193
Done.
require 'rubygems'
require 'spork'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
require 'database_cleaner'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Spork.prefork do
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.use_transactional_fixtures = false
config.include FactoryGirl::Syntax::Methods
config.include(MailerMacros)
config.before(:each) { reset_email }
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
end
Spork.each_run do
FactoryGirl.reload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment