Skip to content

Commit

Permalink
Add simple test.
Browse files Browse the repository at this point in the history
  • Loading branch information
airblade committed Jan 27, 2017
1 parent d616044 commit 38be280
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/chart_helpers_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'test_helper'

require 'chartjs/chart_helpers'

class ChartHelpersTest < Minitest::Test

class Foo
include Chartjs::ChartHelpers

def to_js(element)
to_javascript_string element
end
end

def setup
@subject = Foo.new
end

def test_to_javascript_string
assert_equal '"foo"', @subject.to_js('foo')

assert_equal '["a",42]', @subject.to_js(['a', 42])

assert_equal '{"a":42}', @subject.to_js({'a' => 42})

assert_equal '{"a":function(x) { blah; }}', @subject.to_js({'a' => 'function(x) { blah; }'})

expected = \
'{"a":function(x) {
if (x) {
foo();
}
else {
bar();
}
}
}'

assert_equal expected, @subject.to_js({'a' => <<END})
function(x) {
if (x) {
foo();
}
else {
bar();
}
}
END
end

end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'minitest/autorun'

0 comments on commit 38be280

Please sign in to comment.