Skip to content

Instantly share code, notes, and snippets.

@felipecabargas
Created January 28, 2014 21:23
Show Gist options
  • Save felipecabargas/8676836 to your computer and use it in GitHub Desktop.
Save felipecabargas/8676836 to your computer and use it in GitHub Desktop.
RSpec Looking for spree.admin_items_path (Raise admin_items_path undefined)
<h1>Featured Items</h1>
<table>
<thead>
<tr>
<th>IMAGE</th>
<th>Name</th>
<th>Description</th>
<th>SHOW</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>
</thead>
<tbody>
<% @items.each do |item| %>
<tr>
<td><%= image_tag item.marketing_image, :style => "height: 50px;" %></td>
<td><%= item.name %></td>
<td><%= item.description %></td>
<td><%= link_to 'Show', admin_item_path(item) %></td>
<td><%= link_to 'Edit', edit_admin_item_path(item) %></td>
<td><%= link_to 'Destroy', admin_item_path(item), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Item', new_admin_item_path %>
require 'spec_helper'
describe "spree/admin/items/index" do
before(:each) do
assign(:items, [
stub_model(Spree::Item,
:name => "Name",
:description => "Description"
),
stub_model(Spree::Item,
:name => "Name",
:description => "Description"
)
])
end
it "renders a list of spree/admin/items" do
render
# Run the generator again with the --webrat flag if you want to use webrat matchers
assert_select "tr>td", :text => "Name".to_s, :count => 2
assert_select "tr>td", :text => "Description".to_s, :count => 2
end
end
app/views/spree/admin/items/index.html.erb
config/routes.rb
spec/views/spree/admin/items/index.html.erb_spec.rb
spec/spec_helper.rb
Spree::Core::Engine.routes.draw do
namespace :admin do
resources :items
end
end
# Run Coverage report
require 'simplecov'
SimpleCov.start do
add_filter 'spec/dummy'
add_group 'Controllers', 'app/controllers'
add_group 'Helpers', 'app/helpers'
add_group 'Mailers', 'app/mailers'
add_group 'Models', 'app/models'
add_group 'Views', 'app/views'
add_group 'Libraries', 'lib'
end
# Configure Rails Environment
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../dummy/config/environment.rb', __FILE__)
require 'rspec/rails'
require 'database_cleaner'
require 'ffaker'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
# Requires factories defined in spree_core
require 'spree/testing_support/factories'
require 'spree/testing_support/controller_requests'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/url_helpers'
# Requires factories defined in lib/spree_marketing_featured_items/factories.rb
require 'spree_marketing_featured_items/factories'
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include Devise::TestHelpers, :type => :controller
# == URL Helpers
#
# Allows access to Spree's routes in specs:
#
# visit spree.admin_path
# current_path.should eql(spree.products_path)
config.include Spree::TestingSupport::UrlHelpers
config.include Spree::TestingSupport::ControllerRequests
# == 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
config.mock_with :rspec
config.color = true
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
# to cleanup after each test instead. Without transactional fixtures set to false the records created
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
config.use_transactional_fixtures = false
# Ensure Suite is set to use transactions for speed.
config.before :suite do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with :truncation
end
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
config.before :each do
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
# After each spec clean the database.
config.after :each do
DatabaseCleaner.clean
end
config.fail_fast = ENV['FAIL_FAST'] || false
end
@felipecabargas
Copy link
Author

If I use spree.anything_path in views, all tests runs OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment