Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Convert test suite to MiniTest #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ RSpec::Core::RakeTask.new(:spec)
require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: %i(rubocop spec)
task default: %i(rubocop spec test)

require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
20 changes: 20 additions & 0 deletions test/formtastic_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'
require 'trix_editor_cases'

require 'formtastic'
require 'formtastic/inputs/trix_editor_input'

class FormtasticTest < Minitest::Test
include TrixEditorCases

include Formtastic::Helpers::FormHelper
Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder

private

def render_form
semantic_form_for(@post) do |f|
f.input(:body, as: :trix_editor)
end
end
end
32 changes: 32 additions & 0 deletions test/simple_form_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'test_helper'
require 'trix_editor_cases'

require 'simple_form'

SimpleForm.setup do |config|
config.custom_inputs_namespaces << 'Trix::SimpleForm'
end

require 'trix/simple_form/trix_editor_input'

class SimpleFormTest < Minitest::Test
include TrixEditorCases

include SimpleForm::ActionViewExtensions::FormHelper

def controller
Class.new do
def action_name
'hi'
end
end.new
end

private

def render_form
simple_form_for(@post, url: 'some-url') do |f|
f.input(:body, as: :trix_editor)
end
end
end
5 changes: 5 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'trix'

require 'minitest/autorun'
72 changes: 72 additions & 0 deletions test/trix_editor_cases.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'active_model'
require 'action_view'

class Post
include ActiveModel::Model
attr_accessor :body
end

module RailsCompatibilityLayer
include ActionPack
include ActionView::Context if defined?(ActionView::Context)
include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
include ActionView::Helpers::FormHelper
include ActionDispatch::Routing::PolymorphicRoutes
include ActionView::RecordIdentifier if defined?(ActionView::RecordIdentifier)

require 'rails/dom/testing/assertions'
include Rails::Dom::Testing::Assertions

class Application < Rails::Application
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = 'utf-8'
config.active_support.deprecation = :stderr
config.secret_key_base = 'secret'
config.eager_load = false
end

def protect_against_forgery?
false
end

def posts_path(*)
''
end

def _routes
Rails.application.routes
end
end

module TrixEditorCases
include RailsCompatibilityLayer

def setup
@output_buffer = ''
@post = Post.new(body: 'body')

concat render_form
end

def test_contains_hidden_input_field
assert_select format('input[type="hidden"][id="post_body"][value="%s"]', @post.body)
end

def test_contains_editor_tag
assert_select 'trix-editor[input="post_body"]'
end

def test_contains_class
assert_select 'trix-editor.trix-content'
end

private

def document_root_element
Nokogiri::HTML::Document.parse(@output_buffer).root
end

def render_form
raise NotImplementedError
end
end
7 changes: 7 additions & 0 deletions test/trix_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TrixTest < Minitest::Test
def test_trix_version_not_nil
refute_nil Trix::VERSION
end
end
2 changes: 2 additions & 0 deletions trix.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'bundler', '~> 1.10'
spec.add_development_dependency 'formtastic', '~> 3.0'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'simple_form', '~> 3.5'
spec.add_development_dependency 'rails-dom-testing'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec-rails'
spec.add_development_dependency 'rspec-activemodel-mocks'
Expand Down