Padrino,为Capybara安装应用程序

时间:2016-01-26 14:30:29

标签: rspec capybara padrino

我有一个功能规格: /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

当我进行测试时,我得到:

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

失败的测试,包括:

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('/')

我尝试了各种不同的事情,例如要求“app.rb”和“app.rb”。文件在spec_helper中,然后导致必须在那里也需要active_record,这会导致一个问题,因为它不知道SassInitializer是什么,以及不断。

说实话,我真的不知道我在做什么,或者一切如何融合在一起,所以任何帮助都会非常感激。

回购分支here

1 个答案:

答案 0 :(得分:1)

我从来没有使用过padrino,但是看起来你错过了spec_helper顶部的几行,实际上会加载app资源

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))