Skip to content

Commit

Permalink
Adding test-suite
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspergrubbe committed Mar 17, 2013
1 parent 1431173 commit e4180c7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Rakefile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rake'
require 'rspec/core/rake_task'

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

task :default => :spec
4 changes: 2 additions & 2 deletions lib/embedda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def youtube_player(token)
end

def vimeo_replace(compiled)
compiled.gsub!(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/, vimeo_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/, vimeo_player("\\1"))
compiled.gsub!(/<a[^>]*?vimeo\.com\/(\d+).*?<\/a>/i, vimeo_player("\\1"))
compiled.gsub!(/[http|https]+:\/\/(?:www\.)?vimeo\.com\/(\d+)\S*/i, vimeo_player("\\1"))

return compiled
end
Expand Down
56 changes: 56 additions & 0 deletions spec/embedda_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require "spec_helper"
require 'embedda'

describe "Embedda" do
context "Youtube-link" do
before(:all) do
@embed_string = '<iframe width="560" height="315" src="http://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>'
end

it "should embed when text have a link" do
story = "http://www.youtube.com/watch?v=dQw4w9WgXcQ".embedda
expect(story).to eq(@embed_string)
end

it "should embed when also other text is present around link" do
story = "Hello, my name is Kasper: http://www.youtube.com/watch?v=dQw4w9WgXcQ <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
end

it "should embed when text include anchor tag to Youtube" do
story = "<a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a>".embedda
expect(story).to eq(@embed_string)
end

it "should embed when also other text is present around anchor tag" do
story = "Hello, my name is Kasper: <a href=\"http://www.youtube.com/watch?v=dQw4w9WgXcQ\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
end
end

context "Vimeo-link" do
before(:all) do
@embed_string = "<iframe src=\"http://player.vimeo.com/video/20241459\" width=\"500\" height=\"281\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"
end

it "should embed when text have a link" do
story = "http://vimeo.com/20241459".embedda
expect(story).to eq(@embed_string)
end

it "should embed when also other text is present around link" do
story = "Hello, my name is Kasper: http://vimeo.com/20241459 <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
end

it "should embed when text include anchor tag to Youtube" do
story = "<a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a>".embedda
expect(story).to eq(@embed_string)
end

it "should embed when also other text is present around anchor tag" do
story = "Hello, my name is Kasper: <a href=\"http://vimeo.com/20241459\">Look here for HalfLife3!</a> <br/>And I am embedding links".embedda
expect(story).to eq("Hello, my name is Kasper: #{@embed_string} <br/>And I am embedding links")
end
end
end
20 changes: 20 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'rubygems'
require 'bundler/setup'

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end

0 comments on commit e4180c7

Please sign in to comment.