Skip to content

Commit

Permalink
Guard TEst
Browse files Browse the repository at this point in the history
  • Loading branch information
prihandi committed Mar 18, 2015
1 parent a8a0350 commit fb0c221
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
/log/*
!/log/.keep
/tmp

# Ignore Spring files.
/spring/*.pid
55 changes: 55 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Defines the matching rules for Guard.
guard :minitest, spring: true, all_on_start: false do
watch(%r{^test/(.*)/?(.*)_test\.rb$})
watch('test/test_helper.rb') { 'test' }
watch('config/routes.rb') { integration_tests }
watch(%r{^app/models/(.*?)\.rb$}) do |matches|
"test/models/#{matches[1]}_test.rb"
end
watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches|
resource_tests(matches[1])
end
watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches|
["test/controllers/#{matches[1]}_controller_test.rb"] +
integration_tests(matches[1])
end
watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches|
integration_tests(matches[1])
end
watch('app/views/layouts/application.html.erb') do
'test/integration/site_layout_test.rb'
end
watch('app/helpers/sessions_helper.rb') do
integration_tests << 'test/helpers/sessions_helper_test.rb'
end
watch('app/controllers/sessions_controller.rb') do
['test/controllers/sessions_controller_test.rb',
'test/integration/users_login_test.rb']
end
watch('app/controllers/account_activations_controller.rb') do
'test/integration/users_signup_test.rb'
end
watch(%r{app/views/users/*}) do
resource_tests('users') +
['test/integration/microposts_interface_test.rb']
end
end

# Returns the integration tests corresponding to the given resource.
def integration_tests(resource = :all)
if resource == :all
Dir["test/integration/*"]
else
Dir["test/integration/#{resource}_*.rb"]
end
end

# Returns the controller tests corresponding to the given resource.
def controller_test(resource)
"test/controllers/#{resource}_controller_test.rb"
end

# Returns all tests for the given resource.
def resource_tests(resource)
integration_tests(resource) << controller_test(resource)
end
1 change: 1 addition & 0 deletions config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
Rails.backtrace_cleaner.add_silencer { |line| line =~ /rvm/ }
2 changes: 1 addition & 1 deletion spring/6e00ba5b45f8a500217a7b30c5299e74.pid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27557
30931
16 changes: 9 additions & 7 deletions test/controllers/static_pages_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
require 'test_helper'

class StaticPagesControllerTest < ActionController::TestCase

def setup
@base_title = "Prihandi Tutorial"
end

test "should get home" do
get :home
assert_response :success
assert_select "title", "Home | Prihandi Tutorial"

assert_select "title", "Home | #{@base_title}"
end

test "should get help" do
get :help
assert_response :success
assert_select "title", "Help | Prihandi Tutorial"
assert_select "title", "Help | #{@base_title}"
end

test "should get about" do
get :about
assert_response :success
assert_select "title", "About | Prihandi Tutorial"
assert_select "title", "About | #{@base_title}"
end


end
7 changes: 5 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# require "minitest/reporters"
# Minitest::Reporters.use!

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
# order.
fixtures :all

# Add more helper methods to be used by all tests here...
end
end

0 comments on commit fb0c221

Please sign in to comment.