1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Write rails specs

This commit is contained in:
Takashi Kokubun 2015-03-15 11:43:57 +09:00
parent 36268f5b66
commit ca9b31aeda
10 changed files with 132 additions and 7 deletions

View file

@ -1,10 +1,20 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
desc 'Run benchmarks'
task :bench do
system('TIME=20 bundle exec ruby benchmarks/benchmark.rb')
end
task default: :spec
desc 'Run RSpec code examples'
task :spec do
system('bundle exec rspec --pattern spec/hamlit/**{,/\*/\*\*\}/\*_spec.rb')
end
namespace :rails do
desc 'Run Rails specs'
task :spec do
system('cd spec/rails && rake spec')
end
end
task default: [:spec, 'rails:spec']

View file

@ -8,9 +8,6 @@ module Hamlit
# Use rails-specific generator. This is necessary
# to support block capturing and streaming.
generator: Temple::Generators::RailsOutputBuffer,
# Disable the internal slim capturing.
# Rails takes care of the capturing by itself.
disable_capture: true,
streaming: true,
)
end

View file

@ -0,0 +1,5 @@
class UsersController < ApplicationController
def index
@user = { id: 1, name: 'k0kubun' }
end
end

View file

@ -1,3 +1,5 @@
%span Hamlit
%table
%thead
%tr

View file

@ -0,0 +1,4 @@
%span= params[:q]
%p= @user[:name]
= link_to 'root', root_path

View file

@ -1,3 +1,5 @@
Rails.application.routes.draw do
root to: 'application#index'
resources :users, only: :index
end

16
spec/rails/db/schema.rb Normal file
View file

@ -0,0 +1,16 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 0) do
end

View file

@ -0,0 +1,13 @@
require 'rails_helper'
describe ApplicationController, type: :request do
describe '#index' do
it 'renders views' do
get root_path
expect(response).to be_ok
expect(response).to render_template('application/index')
expect(response).to render_template('layouts/application')
expect(response.body).to include('<span>Hamlit</span>')
end
end
end

View file

@ -0,0 +1,20 @@
require 'rails_helper'
describe UsersController, type: :request do
describe '#index' do
it 'renders params' do
get users_path(q: 'hello')
expect(response.body).to include('<span>hello</span>')
end
it 'renders instance variable' do
get users_path
expect(response.body).to include('<p>k0kubun</p>')
end
it 'renders rails helper' do
get users_path
expect(response.body).to include('<a href="/">root</a>')
end
end
end

View file

@ -0,0 +1,56 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# 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
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
end
# Require factories
Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f }
# Require support files
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }