Permalink
Browse files

split specs in to diff files

  • Loading branch information...
1 parent df89219 commit 1bad17e70390b4fc8cd975d31c2879933fc14fc1 @mvj3 committed Apr 10, 2013
Showing with 116 additions and 102 deletions.
  1. +0 −102 spec/{markdownizer_spec.rb → coderay_spec.rb}
  2. +52 −0 spec/dsl_spec.rb
  3. +54 −0 spec/markdown_spec.rb
  4. +10 −0 spec/pygments_spec.rb
@@ -1,59 +1,7 @@
require 'spec_helper'
describe Markdownizer do
- describe ".markdown(text)" do
- let(:text) { "#My markdown text"}
- context 'when the hierarchy is 0' do
- it 'calls RDiscount to markdownize the text' do
- rdiscount, html_markdown = double(:rdiscount), double(:html_markdown)
-
- RDiscount.should_receive(:new).with(text).and_return rdiscount
- rdiscount.should_receive(:to_html).and_return html_markdown
-
- subject.markdown(text).should == html_markdown
- end
- end
- context 'when the hierarchy is 2' do
- it "converts all headers into 2 levels deeper" do
- my_text = """
- #This is an H1
- ##This is an H2
- ###This is an H3
- """
- result = double :result, :to_html => true
- RDiscount.should_receive(:new).with do |t|
- t.should =~ /###This is an H1/
- t.should =~ /####This is an H2/
- t.should =~ /#####This is an H3/
- end.and_return result
- subject.markdown(my_text, 2)
- end
- it 'still does not convert anything that is not a header' do
- my_text = """
- #This is an H1
- I am talking about my #method
- {% code ruby %}
- \\#My comment
- {% endcode %}
- ###This is an H3
- """
- result = double :result, :to_html => true
- RDiscount.should_receive(:new).with do |t|
- t.should =~ /###This is an H1/
- t.should =~ /#method/
- t.should_not =~ /###method/
- t.should =~ /#My comment/
- t.should_not =~ /###My comment/
- t.should_not =~ /\\#My comment/
- t.should =~ /#####This is an H3/
- end.and_return result
- subject.markdown(my_text, 2)
- end
- end
- end
-
describe ".coderay(text)" do
- Markdownizer.highlight_engine = :coderay
let(:text) { """
#My markdown text
@@ -179,54 +127,4 @@ def function(*args)
end
end
- describe Markdownizer::DSL do
- it 'integrates with ActiveRecord::Base' do
- (class << ActiveRecord::Base; self; end).ancestors.should include(Markdownizer::DSL)
- end
-
- before do
- ActiveRecord::Base.stub(:send)
- @klass = Class.new(ActiveRecord::Base)
- @klass.stub(:column_names) { %w{body rendered_body} }
- end
-
- describe "#markdownize!(attribute)" do
- context "when either of attribute or rendered_attribute does not exist" do
- it 'raises' do
- expect {
- @klass.markdownize! :some_attribute
- }.to raise_error
- end
- end
- context "otherwise" do
- it 'creates a before_save callback for render_attribute' do
- @klass.should_receive(:before_save).with(:render_body)
- @klass.markdownize! :body
- end
- it 'defines this render_attribute method' do
- klass = Class.new do
- extend Markdownizer::DSL
- def self.column_names
- %w{body rendered_body}
- end
- end
-
- klass.stub(:before_save)
- klass.markdownize! :body
-
- raw_body, raw_body_with_code, final_code = double(:raw_body),
- double(:raw_body_with_code),
- double(:final_code)
-
- instance = klass.new
- instance.should_receive(:send).with(:body).and_return raw_body
- Markdownizer.should_receive(:coderay).with(raw_body, {}).and_return raw_body_with_code
- Markdownizer.should_receive(:markdown).with(raw_body_with_code, 0).and_return final_code
-
- instance.should_receive(:send).with(:rendered_body=, final_code)
- instance.render_body
- end
- end
- end
- end
end
View
@@ -0,0 +1,52 @@
+require 'spec_helper'
+
+describe Markdownizer::DSL do
+ it 'integrates with ActiveRecord::Base' do
+ (class << ActiveRecord::Base; self; end).ancestors.should include(Markdownizer::DSL)
+ end
+
+ before do
+ ActiveRecord::Base.stub(:send)
+ @klass = Class.new(ActiveRecord::Base)
+ @klass.stub(:column_names) { %w{body rendered_body} }
+ end
+
+ describe "#markdownize!(attribute)" do
+ context "when either of attribute or rendered_attribute does not exist" do
+ it 'raises' do
+ expect {
+ @klass.markdownize! :some_attribute
+ }.to raise_error
+ end
+ end
+ context "otherwise" do
+ it 'creates a before_save callback for render_attribute' do
+ @klass.should_receive(:before_save).with(:render_body)
+ @klass.markdownize! :body
+ end
+ it 'defines this render_attribute method' do
+ klass = Class.new do
+ extend Markdownizer::DSL
+ def self.column_names
+ %w{body rendered_body}
+ end
+ end
+
+ klass.stub(:before_save)
+ klass.markdownize! :body
+
+ raw_body, raw_body_with_code, final_code = double(:raw_body),
+ double(:raw_body_with_code),
+ double(:final_code)
+
+ instance = klass.new
+ instance.should_receive(:send).with(:body).and_return raw_body
+ Markdownizer.should_receive(:coderay).with(raw_body, {}).and_return raw_body_with_code
+ Markdownizer.should_receive(:markdown).with(raw_body_with_code, 0).and_return final_code
+
+ instance.should_receive(:send).with(:rendered_body=, final_code)
+ instance.render_body
+ end
+ end
+ end
+end
View
@@ -0,0 +1,54 @@
+require 'spec_helper'
+
+describe Markdownizer do
+ describe ".markdown(text)" do
+ let(:text) { "#My markdown text"}
+ context 'when the hierarchy is 0' do
+ it 'calls RDiscount to markdownize the text' do
+ rdiscount, html_markdown = double(:rdiscount), double(:html_markdown)
+
+ RDiscount.should_receive(:new).with(text).and_return rdiscount
+ rdiscount.should_receive(:to_html).and_return html_markdown
+
+ subject.markdown(text).should == html_markdown
+ end
+ end
+ context 'when the hierarchy is 2' do
+ it "converts all headers into 2 levels deeper" do
+ my_text = """
+ #This is an H1
+ ##This is an H2
+ ###This is an H3
+ """
+ result = double :result, :to_html => true
+ RDiscount.should_receive(:new).with do |t|
+ t.should =~ /###This is an H1/
+ t.should =~ /####This is an H2/
+ t.should =~ /#####This is an H3/
+ end.and_return result
+ subject.markdown(my_text, 2)
+ end
+ it 'still does not convert anything that is not a header' do
+ my_text = """
+ #This is an H1
+ I am talking about my #method
+ {% code ruby %}
+ \\#My comment
+ {% endcode %}
+ ###This is an H3
+ """
+ result = double :result, :to_html => true
+ RDiscount.should_receive(:new).with do |t|
+ t.should =~ /###This is an H1/
+ t.should =~ /#method/
+ t.should_not =~ /###method/
+ t.should =~ /#My comment/
+ t.should_not =~ /###My comment/
+ t.should_not =~ /\\#My comment/
+ t.should =~ /#####This is an H3/
+ end.and_return result
+ subject.markdown(my_text, 2)
+ end
+ end
+ end
+end
View
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe Markdownizer do
+ describe ".pygments(text)" do
+ Markdownizer.highlight_engine = :pygments
+
+ Markdownizer.highlight_engine = :coderay # turn back
+ end
+
+end

0 comments on commit 1bad17e

Please sign in to comment.