Search code examples
rspeccapybarapadrino

Padrino, mounting app for Capybara


I have a feature spec: /spec/features/posts_features_spec.rb:

require 'spec_helper'

describe "Displaying Posts" do
  it "can see posts on posts page" do
    Post.create(title: "Title", content: "Content")
    visit '/posts'
    expect(page).to have_content("Title")
    expect(page).to have_content("Content")
  end
end

When I run the test, I get:

WARNING! No apps are mounted. Please, mount apps in `config/apps.rb`

And a failing test, with:

NameError:
       uninitialized constant Post

/spec/spec_helper.rb:

require 'rack/test'
require 'rspec/padrino'
require 'capybara/rspec'

Capybara.app = Padrino.application

RSpec.configure do |config|
  config.include Rack::Test::Methods
  config.include RSpec::Padrino
  config.include Capybara::DSL

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end

/Gemfile:

source 'https://rubygems.org'

# Padrino supports Ruby version 1.9 and later
ruby '2.3.0'

# Project requirements
gem 'rake'

# Component requirements
gem 'bcrypt'
gem 'sass'
gem 'haml'
gem 'activerecord', '>= 3.1', :require => 'active_record'
gem 'sqlite3'

# Test requirements
group :test do
  gem 'shoulda'
  gem 'rack-test', :require => 'rack/test'
  gem 'rspec-padrino'
  gem 'capybara'
end

# Padrino Stable Gem
gem 'padrino', '0.13.1'

/app/app.rb:

module PadrinoBlog
  class App < Padrino::Application
    register SassInitializer
    use ConnectionPoolManagement
    register Padrino::Mailer
    register Padrino::Helpers

    enable :sessions

    get "/" do
      "Hello World!"
    end

    get :about, :map => '/about_us' do
      render :haml, "%p This is a sample blog created to demonstrate how Padrino works!"
    end
  end
end

/config/apps.rb:

Padrino.configure_apps do
  # enable :sessions
  set :session_secret, '67c26da8db30eaf68907e2de05783d33be5e246b87c194f0579bdb589c0761dd'
  set :protection, :except => :path_traversal
  set :protect_from_csrf, true
end

# Mounts the core application for this project

Padrino.mount("PadrinoBlog::Admin", :app_file => Padrino.root('admin/app.rb')).to("/admin")
Padrino.mount('PadrinoBlog::App', :app_file => Padrino.root('app/app.rb')).to('/')

I've tried various different things, such as requiring the 'app.rb' file in spec_helper, which then leads to having to require active_record there too, which then leads to a problem because it doesn't know what SassInitializer is, and on and on.

To be honest, I don't really know what I'm doing with this or how everything fits together, so any help would be much appreciated.

The repo's branch here.


Solution

  • I've never used padrino, but it appears you're missing a few lines from the top of your spec_helper that would actually load up the app resources

    RACK_ENV = 'test' unless defined?(RACK_ENV)
    require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
    Dir[File.expand_path(File.dirname(__FILE__) + "/../app/helpers/**/*.rb")].each(&method(:require))