Skip to content

Commit

Permalink
Add RSpec based specs.
Browse files Browse the repository at this point in the history
Because:
We encountered lately too much 💥 that could be avoided.

This commit:
Is a starting point for testing the gem.
The first thing tested here is the generator, ensuring it creates or
updates the expected files.
  • Loading branch information
Mehdi Lahmam committed May 3, 2015
1 parent 7567068 commit 1c9164b
Show file tree
Hide file tree
Showing 64 changed files with 82 additions and 3,766 deletions.
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
require "bundler/gem_tasks"
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:rspec)

desc 'Run the test suite'
task :default => :rspec
6 changes: 5 additions & 1 deletion foundation-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_dependency "sass", [">= 3.3.0", "< 3.5"]
spec.add_dependency "railties", [">= 3.1.0"]

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "capybara"
spec.add_development_dependency "rake"
spec.add_development_dependency "rails"
spec.add_development_dependency "rspec", "~> 3.2"
end
25 changes: 25 additions & 0 deletions spec/features/generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

feature 'Foundation install succeeds' do
scenario 'stylesheets assets files are added' do
application_css_file = IO.read("#{dummy_app_path}/app/assets/stylesheets/application.css")

expect(File).to exist("#{dummy_app_path}/app/assets/stylesheets/foundation_and_overrides.scss")
expect(application_css_file).to match(/require foundation_and_overrides/)
end

scenario 'javascripts assets files are added' do
application_js_file = IO.read("#{dummy_app_path}/app/assets/javascripts/application.js")

expect(application_js_file).to match(/require foundation/)
expect(application_js_file).to match(Regexp.new(Regexp.escape('$(function(){ $(document).foundation(); });')))
end

scenario 'layout file loads assets' do
layout_file = IO.read("#{dummy_app_path}/app/views/layouts/application.html.erb")

expect(layout_file).to match(/stylesheet_link_tag "application"/)
expect(layout_file).to match(/javascript_include_tag "vendor\/modernizr"/)
expect(layout_file).to match(/javascript_include_tag "application/)
end
end
19 changes: 19 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'capybara/rspec'
require 'bundler/setup'

Bundler.require(:default, :test)

Dir['./spec/support/**/*.rb'].each { |file| require file }

RSpec.configure do |config|
config.include FoundationRailsTestHelpers

config.before(:all) do
create_dummy_app
install_foundation
end

config.after(:all) do
remove_dummy_app
end
end
25 changes: 25 additions & 0 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module FoundationRailsTestHelpers
def create_dummy_app
FileUtils.cd(tmp_path) do
%x(rails new dummy --skip-active-record --skip-test-unit --skip-spring)
end
end

def remove_dummy_app
FileUtils.rm_rf(dummy_app_path)
end

def install_foundation
FileUtils.cd(dummy_app_path) do
%x(rails g foundation:install -f 2>&1)
end
end

def dummy_app_path
File.join(tmp_path, 'dummy')
end

def tmp_path
@tmp_path ||= File.join(File.dirname(__FILE__), '..')
end
end
17 changes: 0 additions & 17 deletions test/dummy/.gitignore

This file was deleted.

45 changes: 0 additions & 45 deletions test/dummy/Gemfile

This file was deleted.

28 changes: 0 additions & 28 deletions test/dummy/README.rdoc

This file was deleted.

6 changes: 0 additions & 6 deletions test/dummy/Rakefile

This file was deleted.

Empty file removed test/dummy/app/assets/images/.keep
Empty file.
19 changes: 0 additions & 19 deletions test/dummy/app/assets/javascripts/application.js

This file was deleted.

17 changes: 0 additions & 17 deletions test/dummy/app/assets/stylesheets/application.css

This file was deleted.

Loading

0 comments on commit 1c9164b

Please sign in to comment.