Created
November 16, 2012 06:30
-
-
Save JuliaLovel/4084815 to your computer and use it in GitHub Desktop.
Rspec includes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "ProductPage", :type => :feature do | |
include ActionView::Helpers::UrlHelper | |
include ActionView::Helpers::AssetTagHelper | |
before do | |
@product = Spree::Product.last | |
visit "/products/#{@product.permalink}" | |
end | |
it "should have product name" do | |
page.should have_selector('h1', text: "#{@product.name}") | |
end | |
it "should have product sku" do | |
page.should have_selector('span.skew', text: "#{@product.sku}") | |
end | |
it "should have product description" do | |
page.should have_selector('div#description', content: @product.description.gsub(/^(.*)$/, '<p>\1</p>').html_safe) | |
end | |
it "should display similar products" do | |
#Assign @similar_products the same way as view file | |
@similar_taxon = @product.taxons.first | |
@similar_products = (@product.similar_products.length > 0) ? @product.similar_products.first(3) : Spree::Product.in_taxon(@similar_taxon).limit(3) | |
if @similar_products.length >= 3 | |
#Display a similar products container div, only if there are 3 similar products | |
page.should have_selector(".title-bar h4", :content => "Similar Products") | |
#Anything else that doesn't need to be looped goes here... | |
#In a loop, check for the divs corresponding to each similar product | |
@similar_products.each do |sp| | |
page.should have_content(link_to(image_tag(sp.images[0].attachment.url(:mini)), product_path(sp))) | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Failures: | |
1) ProductPage should have product name | |
Failure/Error: page.should have_selector('h1', text: "#{@product.name}") | |
Capybara::ExpectationNotMet: | |
expected to find css "h1" with text "100 feet of 22 Ga. Tin Plated, Aerospace Grade, Tefzel Wire, 100 Feet" but there were no matches. Also found "100 feet of 22 Ga. Tin Plated, Aerospace Grade, Tefzel Wire, 100 Feet", which matched the selector but not all filters. | |
# ./spec/features/product_spec.rb:18:in `block (2 levels) in <top (required)>' | |
2) ProductPage should have product description | |
Failure/Error: page.should have_selector('div#description', content: @product.description.gsub(/^(.*)$/, '<p>\1</p>').html_safe) | |
ArgumentError: | |
invalid keys :content, should be one of :text, :visible, :between, :count, :maximum, :minimum | |
# ./spec/features/product_spec.rb:26:in `block (2 levels) in <top (required)>' | |
3) ProductPage should display similar products | |
Failure/Error: page.should have_selector(".title-bar h4", :content => "Similar Products") | |
ArgumentError: | |
invalid keys :content, should be one of :text, :visible, :between, :count, :maximum, :minimum | |
# ./spec/features/product_spec.rb:37:in `block (2 levels) in <top (required)>' | |
4) PurchaseOrderMailer po_email renders the headers | |
Failure/Error: let(:mail) { PurchaseOrderMailer.po_email } | |
ArgumentError: | |
wrong number of arguments (0 for 6) | |
# ./spec/mailers/purchase_order_mailer_spec.rb:5:in `block (3 levels) in <top (required)>' | |
# ./spec/mailers/purchase_order_mailer_spec.rb:8:in `block (3 levels) in <top (required)>' | |
5) PurchaseOrderMailer po_email renders the body | |
Failure/Error: let(:mail) { PurchaseOrderMailer.po_email } | |
ArgumentError: | |
wrong number of arguments (0 for 6) | |
# ./spec/mailers/purchase_order_mailer_spec.rb:5:in `block (3 levels) in <top (required)>' | |
# ./spec/mailers/purchase_order_mailer_spec.rb:14:in `block (3 levels) in <top (required)>' | |
6) Spree::Order line_items should have relations created after order completion | |
Failure/Error: if Spree::Relation.where('relatable_id = ? AND related_id = ?', @order.line_items.first.variant.product.id, @order.line_items.first.variant.product.id).nil? | |
NoMethodError: | |
You have a nil object when you didn't expect it! | |
You might have expected an instance of Array. | |
The error occurred while evaluating nil.product | |
# ./spec/models/order_spec.rb:14:in `block (3 levels) in <top (required)>' | |
Finished in 4.3 seconds | |
7 examples, 6 failures | |
Failed examples: | |
rspec ./spec/features/product_spec.rb:17 # ProductPage should have product name | |
rspec ./spec/features/product_spec.rb:25 # ProductPage should have product description | |
rspec ./spec/features/product_spec.rb:30 # ProductPage should display similar products | |
rspec ./spec/mailers/purchase_order_mailer_spec.rb:7 # PurchaseOrderMailer po_email renders the headers | |
rspec ./spec/mailers/purchase_order_mailer_spec.rb:13 # PurchaseOrderMailer po_email renders the body | |
rspec ./spec/models/order_spec.rb:12 # Spree::Order line_items should have relations created after order completion | |
Randomized with seed 54566 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is copied to spec/ when you run 'rails generate rspec:install' | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
require 'rspec/autorun' | |
require 'capybara/rails' | |
require 'capybara/dsl' | |
require 'capybara/rspec' | |
# Requires supporting ruby files with custom matchers and macros, etc, | |
# in spec/support/ and its subdirectories. | |
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} | |
RSpec.configure do |config| | |
# ## Mock Framework | |
# | |
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: | |
# | |
# config.mock_with :mocha | |
# config.mock_with :flexmock | |
# config.mock_with :rr | |
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures | |
config.fixture_path = "#{::Rails.root}/spec/fixtures" | |
# If you're not using ActiveRecord, or you'd prefer not to run each of your | |
# examples within a transaction, remove the following line or assign false | |
# instead of true. | |
config.use_transactional_fixtures = true | |
# If true, the base class of anonymous controllers will be inferred | |
# automatically. This will be the default behavior in future versions of | |
# rspec-rails. | |
config.infer_base_class_for_anonymous_controllers = false | |
# Run specs in random order to surface order dependencies. If you find an | |
# order dependency and want to debug it, you can fix the order by providing | |
# the seed, which is printed after each run. | |
# --seed 1234 | |
config.order = "random" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment