test/addthis_test.rb in jaap3-addthis-0.2.1 vs test/addthis_test.rb in jaap3-addthis-0.5.0
- old
+ new
@@ -25,10 +25,15 @@
@output = method(m).call("http://example.com")
@output_lines = @output.split("\n")
end
should_set_script_src_to Jaap3::Addthis::DEFAULT_OPTIONS[:script_src]
+
+ [:brand, :header_color, :header_background,
+ :offset_top, :offset_left, :hover_delay].each do |attribute|
+ should_not_customize attribute
+ end
should "start with an html comment" do
assert_equal "<!-- AddThis Button BEGIN -->", @output_lines.first
end
@@ -79,71 +84,157 @@
[:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
context "the output of #{m}" do
setup { @output = method(m).call("http://example.com") }
- should "set addthis_pub to test_publisher" do
- assert_match 'var addthis_pub="test_publisher";', @output
- end
+ should_customize :pub, "test_publisher"
end
end
context "a feed button" do
setup { @output = addthis_feed_button("http://example.com") }
should_set_href_to "http://www.addthis.com/feed.php?pub=test_publisher&h1=http://example.com&t1="
end
+
+ context "in turn overwritten by options hash" do
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "the output of #{m}" do
+ setup { @output = method(m).call("http://example.com", :publisher => "another_publisher") }
+
+ should_customize :pub, "another_publisher"
+ end
+ end
+
+ context "a feed button" do
+ setup { @output = addthis_feed_button("http://example.com", :publisher => "another_publisher") }
+
+ should_set_href_to "http://www.addthis.com/feed.php?pub=another_publisher&h1=http://example.com&t1="
+ end
+ end
end
context "with altered script_src" do
setup { Jaap3::Addthis::DEFAULT_OPTIONS[:script_src] = "http://example.com/example.js" }
[:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
context "the output of #{m}" do
- setup do
- @output = method(m).call("http://example.com")
- @output_lines = @output.split("\n")
- end
+ setup { @output = method(m).call("http://example.com") }
should_set_script_src_to "http://example.com/example.js"
end
end
context "in turn overwritten by options hash" do
[:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
context "the output of #{m}" do
- setup do
- @output = method(m).call("http://example.com", :script_src => "http://www.example.com/example.js")
- @output_lines = @output.split("\n")
- end
+ setup { @output = method(m).call("http://example.com", :script_src => "http://www.example.com/example.js") }
should_set_script_src_to "http://www.example.com/example.js"
end
end
end
end
+ context "when overwriting alt and title" do
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "the output of #{m}" do
+ setup { @output = method(m).call("http://example.com", :alt => "Example", :title => "Example title") }
+
+ should_set_title_to "Example title"
+ should_set_alt_to "Example"
+ end
+ end
+ end
+
context "when setting secure to true" do
[:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
context "by using the options hash the output of #{m}" do
- setup do
- @output = method(m).call("http://example.com", :secure => true)
- @output_lines = @output.split("\n")
- end
+ setup { @output = method(m).call("http://example.com", :secure => true) }
should_set_script_src_to "https://secure.addthis.com/js/200/addthis_widget.js"
end
end
[:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
context "by altering the defaults the output of #{m}" do
setup do
Jaap3::Addthis::DEFAULT_OPTIONS[:secure] = true
@output = method(m).call("http://example.com")
- @output_lines = @output.split("\n")
end
should_set_script_src_to "https://secure.addthis.com/js/200/addthis_widget.js"
+ end
+ end
+ end
+
+ context "with a block" do
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "the output of #{m}" do
+ setup do
+ @output = method(m).call("http://example.com") do
+ "Click here to AddThis"
+ end
+ end
+
+ should "contain the custom text" do
+ assert_match(/<a[^>]+>Click here to AddThis<\/a>/, @output)
+ end
+ end
+ end
+ end
+
+ context "with changed default html" do
+ setup do
+ Jaap3::Addthis::BOOKMARK_BUTTON_DEFAULTS[:button_html] = "Click here to AddThis"
+ Jaap3::Addthis::FEED_BUTTON_DEFAULTS[:button_html] = "Click here to AddThis"
+ Jaap3::Addthis::EMAIL_BUTTON_DEFAULTS[:button_html] = "Click here to AddThis"
+ end
+
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "the output of #{m}" do
+ setup { @output = method(m).call("http://example.com") }
+
+ should "contain the custom text" do
+ assert_match(/<a[^>]+>Click here to AddThis<\/a>/, @output)
+ end
+ end
+ end
+ end
+
+ context "tricked out with options" do
+ options = {
+ :brand => "Example brand",
+ :header_color => "white",
+ :header_background => "black",
+ :offset_top => 40,
+ :offset_left => 60,
+ :hover_delay => 200
+ }
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "the output of #{m}" do
+ setup do
+ @output = method(m).call("http://example.com", options)
+ end
+
+ options.each_pair do |attribute, value|
+ should_customize attribute, value
+ end
+ end
+ end
+
+ [:addthis_bookmark_button, :addthis_feed_button, :addthis_email_button].each do |m|
+ context "by changing the defaults the output of #{m}" do
+ setup do
+ options.each_pair do |attribute, value|
+ Jaap3::Addthis::DEFAULT_OPTIONS[attribute] = value
+ end
+ @output = method(m).call("http://example.com", options)
+ end
+
+ options.each_pair do |attribute, value|
+ should_customize attribute, value
+ end
end
end
end
end
\ No newline at end of file