mist 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +192 -0
  7. data/README.md +108 -0
  8. data/Rakefile +9 -0
  9. data/app/assets/images/mist/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  10. data/app/assets/images/mist/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  11. data/app/assets/images/mist/ui-bg_flat_10_000000_40x100.png +0 -0
  12. data/app/assets/images/mist/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  13. data/app/assets/images/mist/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  14. data/app/assets/images/mist/ui-bg_glass_65_ffffff_1x400.png +0 -0
  15. data/app/assets/images/mist/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  16. data/app/assets/images/mist/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  17. data/app/assets/images/mist/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  18. data/app/assets/images/mist/ui-icons_222222_256x240.png +0 -0
  19. data/app/assets/images/mist/ui-icons_228ef1_256x240.png +0 -0
  20. data/app/assets/images/mist/ui-icons_ef8c08_256x240.png +0 -0
  21. data/app/assets/images/mist/ui-icons_ffd27a_256x240.png +0 -0
  22. data/app/assets/images/mist/ui-icons_ffffff_256x240.png +0 -0
  23. data/app/assets/javascripts/mist/jquery-ui-1.8.17.custom.min.js +356 -0
  24. data/app/assets/javascripts/mist/posts.js.coffee +3 -0
  25. data/app/assets/javascripts/mist_core.js +3 -0
  26. data/app/assets/stylesheets/mist/posts.css.sass +97 -0
  27. data/app/assets/stylesheets/mist/scaffolds.css.scss +56 -0
  28. data/app/assets/stylesheets/mist/ui-lightness/jquery-ui-1.8.17.custom.css +565 -0
  29. data/app/assets/stylesheets/mist_core.css +4 -0
  30. data/app/controllers/application_controller.rb +3 -0
  31. data/app/controllers/mist/posts_controller.rb +130 -0
  32. data/app/helpers/mist/posts_helper.rb +61 -0
  33. data/app/mailers/.gitkeep +0 -0
  34. data/app/models/.gitkeep +0 -0
  35. data/app/models/mist/post.rb +240 -0
  36. data/app/models/mist/post_sweeper.rb +63 -0
  37. data/app/views/layouts/mist/posts.html.erb +66 -0
  38. data/app/views/mist/posts/_form.html.erb +55 -0
  39. data/app/views/mist/posts/_post.html.erb +19 -0
  40. data/app/views/mist/posts/_sidebar_title.html.erb +5 -0
  41. data/app/views/mist/posts/edit.html.erb +16 -0
  42. data/app/views/mist/posts/feed.atom.builder +17 -0
  43. data/app/views/mist/posts/index.html.erb +31 -0
  44. data/app/views/mist/posts/new.html.erb +15 -0
  45. data/app/views/mist/posts/show.html.erb +3 -0
  46. data/config/cucumber.yml +8 -0
  47. data/config/environment.rb +1 -0
  48. data/config/routes.rb +7 -0
  49. data/features/atom_feed.feature +20 -0
  50. data/features/authorize_create_post.feature +14 -0
  51. data/features/authorize_destroy_post.feature +27 -0
  52. data/features/authorize_update_post.feature +28 -0
  53. data/features/authorize_view_unpublished.feature +22 -0
  54. data/features/create_post.feature +13 -0
  55. data/features/destroy_post.feature +13 -0
  56. data/features/format_with_markdown.feature +13 -0
  57. data/features/popular_posts.feature +35 -0
  58. data/features/recent_posts.feature +28 -0
  59. data/features/similar_posts.feature +43 -0
  60. data/features/step_definitions/authorization_steps.rb +17 -0
  61. data/features/step_definitions/filesystem_steps.rb +13 -0
  62. data/features/step_definitions/page_steps.rb +43 -0
  63. data/features/step_definitions/post_steps.rb +58 -0
  64. data/features/step_definitions/sidebar_steps.rb +21 -0
  65. data/features/support/env.rb +58 -0
  66. data/features/support/setup.rb +15 -0
  67. data/features/update_post.feature +19 -0
  68. data/gemfiles/common +20 -0
  69. data/gemfiles/rails-3.1.3 +4 -0
  70. data/gemfiles/rails-3.1.3.lock +195 -0
  71. data/gemfiles/rails-3.2.0 +4 -0
  72. data/lib/generators/mist/USAGE +13 -0
  73. data/lib/generators/mist/setup_generator.rb +21 -0
  74. data/lib/generators/mist/templates/initializer.rb +17 -0
  75. data/lib/generators/mist/templates/mist.css.scss +2 -0
  76. data/lib/generators/mist/templates/mist.js.coffee +1 -0
  77. data/lib/generators/mist/views_generator.rb +11 -0
  78. data/lib/mist.rb +26 -0
  79. data/lib/mist/code_example_parser.rb +86 -0
  80. data/lib/mist/configuration.rb +68 -0
  81. data/lib/mist/configuration/author.rb +8 -0
  82. data/lib/mist/engine.rb +12 -0
  83. data/lib/mist/git_file_system_history.rb +66 -0
  84. data/lib/mist/git_model.rb +154 -0
  85. data/lib/mist/git_model/attributes.rb +21 -0
  86. data/lib/mist/git_model/class_methods.rb +141 -0
  87. data/lib/mist/permalink.rb +5 -0
  88. data/lib/mist/repository.rb +15 -0
  89. data/lib/mist/version.rb +8 -0
  90. data/mist.gemspec +33 -0
  91. data/spec/controllers/posts_controller_spec.rb +263 -0
  92. data/spec/dummy_rails_app/app/assets/javascripts/mist.js.coffee +1 -0
  93. data/spec/dummy_rails_app/app/assets/stylesheets/mist.css.scss +2 -0
  94. data/spec/dummy_rails_app/app/views/layouts/mist/posts.html.erb +60 -0
  95. data/spec/dummy_rails_app/config.ru +4 -0
  96. data/spec/dummy_rails_app/config/application.rb +48 -0
  97. data/spec/dummy_rails_app/config/boot.rb +7 -0
  98. data/spec/dummy_rails_app/config/database.yml +28 -0
  99. data/spec/dummy_rails_app/config/environment.rb +5 -0
  100. data/spec/dummy_rails_app/config/environments/development.rb +32 -0
  101. data/spec/dummy_rails_app/config/environments/production.rb +60 -0
  102. data/spec/dummy_rails_app/config/environments/test.rb +42 -0
  103. data/spec/dummy_rails_app/config/initializers/active_gist_credentials.rb +8 -0
  104. data/spec/dummy_rails_app/config/initializers/backtrace_silencers.rb +7 -0
  105. data/spec/dummy_rails_app/config/initializers/inflections.rb +10 -0
  106. data/spec/dummy_rails_app/config/initializers/mime_types.rb +5 -0
  107. data/spec/dummy_rails_app/config/initializers/mist.rb +17 -0
  108. data/spec/dummy_rails_app/config/initializers/secret_token.rb +7 -0
  109. data/spec/dummy_rails_app/config/initializers/session_store.rb +8 -0
  110. data/spec/dummy_rails_app/config/initializers/wrap_parameters.rb +14 -0
  111. data/spec/dummy_rails_app/config/locales/en.yml +5 -0
  112. data/spec/dummy_rails_app/config/routes.rb +3 -0
  113. data/spec/dummy_rails_app/db/schema.rb +22 -0
  114. data/spec/dummy_rails_app/db/seeds.rb +7 -0
  115. data/spec/dummy_rails_app/doc/README_FOR_APP +2 -0
  116. data/spec/dummy_rails_app/lib/assets/.gitkeep +0 -0
  117. data/spec/dummy_rails_app/lib/tasks/.gitkeep +0 -0
  118. data/spec/dummy_rails_app/lib/tasks/cucumber.rake +65 -0
  119. data/spec/dummy_rails_app/public/404.html +26 -0
  120. data/spec/dummy_rails_app/public/422.html +26 -0
  121. data/spec/dummy_rails_app/public/500.html +26 -0
  122. data/spec/dummy_rails_app/public/favicon.ico +0 -0
  123. data/spec/dummy_rails_app/public/robots.txt +5 -0
  124. data/spec/dummy_rails_app/script/cucumber +10 -0
  125. data/spec/dummy_rails_app/script/rails +6 -0
  126. data/spec/dummy_rails_app/vendor/assets/stylesheets/.gitkeep +0 -0
  127. data/spec/dummy_rails_app/vendor/plugins/.gitkeep +0 -0
  128. data/spec/factories/posts.rb +8 -0
  129. data/spec/fixtures/gist_404 +6 -0
  130. data/spec/fixtures/gist_with_1_code_example +66 -0
  131. data/spec/helpers/posts_helper_spec.rb +64 -0
  132. data/spec/lib/mist/code_example_parser_spec.rb +135 -0
  133. data/spec/lib/mist/configuration_spec.rb +88 -0
  134. data/spec/lib/mist/permalink_spec.rb +17 -0
  135. data/spec/lib/mist/repository_spec.rb +20 -0
  136. data/spec/models/mist/git_model_spec.rb +260 -0
  137. data/spec/models/mist/post_spec.rb +575 -0
  138. data/spec/requests/posts_caching_spec.rb +152 -0
  139. data/spec/spec_helper.rb +20 -0
  140. data/spec/support/cache_helpers.rb +71 -0
  141. data/spec/support/config.rb +42 -0
  142. data/spec/support/fakeweb.rb +3 -0
  143. data/spec/views/mist/posts/edit.html.erb_spec.rb +11 -0
  144. data/spec/views/mist/posts/index.html.erb_spec.rb +27 -0
  145. data/spec/views/mist/posts/new.html.erb_spec.rb +15 -0
  146. data/spec/views/mist/posts/show.html.erb_spec.rb +11 -0
  147. metadata +371 -0
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
File without changes
File without changes
@@ -0,0 +1,65 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
+
10
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
+
13
+ begin
14
+ require 'cucumber/rake/task'
15
+
16
+ namespace :cucumber do
17
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
+ t.fork = true # You may get faster startup if you set this to false
20
+ t.profile = 'default'
21
+ end
22
+
23
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
+ t.binary = vendored_cucumber_bin
31
+ t.fork = true # You may get faster startup if you set this to false
32
+ t.profile = 'rerun'
33
+ end
34
+
35
+ desc 'Run all features'
36
+ task :all => [:ok, :wip]
37
+
38
+ task :statsetup do
39
+ require 'rails/code_statistics'
40
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
+ end
43
+ end
44
+ desc 'Alias for cucumber:ok'
45
+ task :cucumber => 'cucumber:ok'
46
+
47
+ task :default => :cucumber
48
+
49
+ task :features => :cucumber do
50
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51
+ end
52
+
53
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54
+ task 'db:test:prepare' do
55
+ end
56
+
57
+ task :stats => 'cucumber:statsetup'
58
+ rescue LoadError
59
+ desc 'cucumber rake task not available (cucumber not installed)'
60
+ task :cucumber do
61
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-Agent: *
5
+ # Disallow: /
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
4
+ if vendored_cucumber_bin
5
+ load File.expand_path(vendored_cucumber_bin)
6
+ else
7
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
8
+ require 'cucumber'
9
+ load Cucumber::BINARY
10
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
@@ -0,0 +1,8 @@
1
+ # Read about factories at http://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :post, :class => Mist::Post do
5
+ title "MyString"
6
+ content "This is content"
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ HTTP/1.1 404 Resource Not Found
2
+ Link: <https://api.github.com/resource?page=2>; rel="next",
3
+ <https://api.github.com/resource?page=5>; rel="last"
4
+ X-RateLimit-Limit: 5000
5
+ X-RateLimit-Remaining: 4999
6
+ Content-type: application/json; charset=utf-8
@@ -0,0 +1,66 @@
1
+ HTTP/1.1 200 OK
2
+ Link: <https://api.github.com/resource?page=2>; rel="next",
3
+ <https://api.github.com/resource?page=5>; rel="last"
4
+ X-RateLimit-Limit: 5000
5
+ X-RateLimit-Remaining: 4999
6
+ Content-type: application/json; charset=utf-8
7
+
8
+ {
9
+ "url": "https://api.github.com/gists/1",
10
+ "id": "1",
11
+ "description": "Code examples for blog post: Code Example",
12
+ "public": true,
13
+ "user": {
14
+ "login": "octocat",
15
+ "id": 1,
16
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
17
+ "gravatar_id": "somehexcode",
18
+ "url": "https://api.github.com/users/octocat"
19
+ },
20
+ "files": {
21
+ "test.rb": {
22
+ "size": 932,
23
+ "filename": "test.rb",
24
+ "raw_url": "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/test.rb",
25
+ "content": "def one\n :one\nend\n"
26
+ }
27
+ },
28
+ "comments": 0,
29
+ "html_url": "https://gist.github.com/2",
30
+ "git_pull_url": "git://gist.github.com/2.git",
31
+ "git_push_url": "git@gist.github.com:2.git",
32
+ "created_at": "2010-04-14T02:15:15Z",
33
+ "updated_at": "2010-04-14T02:15:15Z",
34
+ "forks": [
35
+ {
36
+ "user": {
37
+ "login": "octocat",
38
+ "id": 1,
39
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
40
+ "gravatar_id": "somehexcode",
41
+ "url": "https://api.github.com/users/octocat"
42
+ },
43
+ "url": "https://api.github.com/gists/5",
44
+ "created_at": "2011-04-14T16:00:49Z"
45
+ }
46
+ ],
47
+ "history": [
48
+ {
49
+ "url": "https://api.github.com/gists/1/57a7f021a713b1c5a6a199b54cc514735d2d462f",
50
+ "version": "57a7f021a713b1c5a6a199b54cc514735d2d462f",
51
+ "user": {
52
+ "login": "octocat",
53
+ "id": 1,
54
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
55
+ "gravatar_id": "somehexcode",
56
+ "url": "https://api.github.com/users/octocat"
57
+ },
58
+ "change_status": {
59
+ "deletions": 0,
60
+ "additions": 180,
61
+ "total": 180
62
+ },
63
+ "committed_at": "2010-04-14T02:15:15Z"
64
+ }
65
+ ]
66
+ }
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mist::PostsHelper do
4
+ describe "with 7 posts" do
5
+ before do
6
+ %w(one two three four five six seven).each do |title|
7
+ Mist::Post.create!(:title => title, :content => "#{title} content", :published => true)
8
+ end
9
+ end
10
+
11
+ it "should only return 5 posts" do
12
+ helper.recent_posts.should have(5).items
13
+ end
14
+
15
+ it "should include the last 5 posts" do
16
+ helper.recent_posts[0].title.should == "seven"
17
+ helper.recent_posts[1].title.should == "six"
18
+ helper.recent_posts[2].title.should == "five"
19
+ helper.recent_posts[3].title.should == "four"
20
+ helper.recent_posts[4].title.should == "three"
21
+ end
22
+ end
23
+
24
+ describe "if authorized" do
25
+ before { Mist.authorize(:create_post, :edit_post) { true } }
26
+
27
+ it "should produce a single authorized link" do
28
+ link = helper.authorized_link :create_post, "Caption", "/"
29
+ link.should == helper.link_to("Caption", "/")
30
+ end
31
+
32
+ it "should produce multiple joined authorized links" do
33
+ links = helper.authorized_links 'sep', [:create_post, "Create", "/"], [:edit_post, "Edit", "/"]
34
+ links.should == [helper.link_to("Create", "/"), helper.link_to("Edit", "/")].join('sep')
35
+ end
36
+ end
37
+
38
+ describe "if not authorized" do
39
+ it "should produce no authorized link" do
40
+ link = helper.authorized_link :create_post, "Caption", "/"
41
+ link.should == ""
42
+ end
43
+
44
+ it "should not produce multiple joined authorized links" do
45
+ links = helper.authorized_links 'sep', [:create_post, "Caption", "/"], [:create_post, "Caption", "/"]
46
+ links.should == ""
47
+ end
48
+ end
49
+
50
+ describe "if partially authorized" do
51
+ before { Mist.authorize(:create_post) { true } }
52
+
53
+ it "should produce a single authorized link" do
54
+ link = helper.authorized_link :create_post, "Caption", "/"
55
+ link.should == helper.link_to("Caption", "/")
56
+ end
57
+
58
+ it "should produce two joined authorized links instead of three" do
59
+ links = helper.authorized_links 'sep', [:create_post, "One", "/"], [:edit_post, "Two", "/"],
60
+ [:create_post, "Three", "/"]
61
+ links.should == [helper.link_to("One", "/"), helper.link_to("Three", "/")].join('sep')
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mist::CodeExampleParser do
4
+ describe "with nil arg" do
5
+ subject { Mist::CodeExampleParser.new(nil).examples }
6
+ it { should have(0).examples }
7
+ end
8
+
9
+ describe "with text but no examples" do
10
+ subject { Mist::CodeExampleParser.new("this is text").examples }
11
+ it { should have(0).examples }
12
+ end
13
+
14
+ describe "with text and blank lines but no examples" do
15
+ subject { Mist::CodeExampleParser.new("this is\n\ntext").examples }
16
+ it { should have(0).examples }
17
+ end
18
+
19
+ describe "with crlf" do
20
+ subject { Mist::CodeExampleParser.new("# Test\r\n\r\n file: test.rb\r\n one = :one\r\n") }
21
+
22
+ it "should strip cr from filenames" do
23
+ subject.examples[0].filename.should == "test.rb"
24
+ end
25
+
26
+ it "should not leave cr or lf preceding code" do
27
+ subject.examples[0][0].should_not == ?\r
28
+ subject.examples[0][0].should_not == ?\n
29
+ end
30
+ end
31
+
32
+ let(:basic_code) { " def one\n 1\n end" }
33
+ let(:content) { basic_code }
34
+ subject { Mist::CodeExampleParser.new(content).examples }
35
+
36
+ describe "with 1 code example with explicit filename" do
37
+ let(:content) { "test1\n file: filename.rb\n#{basic_code}\ntest2" }
38
+ it "should set filename" do
39
+ subject[0].filename.should == "filename.rb"
40
+ end
41
+ it "should not have filename in content" do
42
+ subject[0].should == "def one\n 1\nend\n"
43
+ end
44
+ it "should not affect its range" do
45
+ content[subject[0].offset].should == " file: filename.rb\n#{basic_code}\n"
46
+ end
47
+ end
48
+
49
+ describe "2 examples with different filenames" do
50
+ let(:content) { " file: file1.rb\n#{basic_code}\n\n file: file2.rb\n#{basic_code}" }
51
+ it "should not merge the examples" do
52
+ subject[0].filename.should == 'file1.rb'
53
+ subject[1].filename.should == 'file2.rb'
54
+ end
55
+ end
56
+
57
+ describe "with 1 code example but no text" do
58
+ it { should have(1).example }
59
+
60
+ it "should have a default filename" do
61
+ subject[0].filename.should == "Example 1"
62
+ end
63
+
64
+ it "should define a range" do
65
+ content[subject[0].offset].should == basic_code
66
+ end
67
+
68
+ it "should outdent code appropriately" do
69
+ subject[0].should == "def one\n 1\nend"
70
+ end
71
+ end
72
+
73
+ describe "with text preceding 1 code example" do
74
+ let(:content) { "this is text\n#{basic_code}" }
75
+
76
+ it { should have(1).example }
77
+
78
+ it "should outdent code" do
79
+ subject[0].should == "def one\n 1\nend"
80
+ end
81
+
82
+ it "should define a range" do
83
+ content[subject[0].offset].should == basic_code
84
+ end
85
+ end
86
+
87
+ describe "with text proceding 1 code example" do
88
+ let(:content) { "#{basic_code}\nthis is text" }
89
+
90
+ it { should have(1).example }
91
+
92
+ it "should outdent code" do
93
+ subject[0].should == "def one\n 1\nend\n"
94
+ end
95
+
96
+ it "should define a range" do
97
+ content[subject[0].offset].should == "#{basic_code}\n"
98
+ end
99
+ end
100
+
101
+ describe "with 2 code examples separated by text" do
102
+ let(:content) { "#{basic_code}\nthis is text\n#{basic_code}" }
103
+
104
+ it { should have(2).examples }
105
+
106
+ it "should give default filenames" do
107
+ subject[0].filename.should == "Example 1"
108
+ subject[1].filename.should == "Example 2"
109
+ end
110
+
111
+ it "should outdent code" do
112
+ subject[0].should == "def one\n 1\nend\n"
113
+ subject[1].should == "def one\n 1\nend"
114
+ end
115
+
116
+ it "should define a range" do
117
+ content[subject[0].offset].should == "#{basic_code}\n"
118
+ content[subject[1].offset].should == "#{basic_code}"
119
+ end
120
+ end
121
+
122
+ describe "1 example with a blank line in it" do
123
+ let(:content) { "#{basic_code}\n\n#{basic_code}" }
124
+
125
+ it { should have(1).example }
126
+
127
+ it "should outdent code" do
128
+ subject[0].should == "def one\n 1\nend\n\ndef one\n 1\nend"
129
+ end
130
+
131
+ it "should define a range" do
132
+ content[subject[0].offset].should == content
133
+ end
134
+ end
135
+ end