From 86cd62608492b049f9d0c2270f4bae14b2bc1584 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Wed, 29 May 2013 10:59:03 -0400 Subject: [PATCH] write some file change and deletion tests for better data coverage --- .gitignore | 1 + .simplecov | 6 -- middleman-core/features/data.feature | 26 ++++++++- .../basic-data-app/source/data.html.erb | 6 +- .../basic-data-app/source/data3.html.erb | 6 +- .../lib/middleman-core/application.rb | 2 +- middleman-core/lib/middleman-core/util.rb | 57 ------------------- middleman.sublime-project | 16 ++++++ 8 files changed, 53 insertions(+), 67 deletions(-) delete mode 100644 .simplecov create mode 100644 middleman.sublime-project diff --git a/.gitignore b/.gitignore index 2b4e408c..ca386f77 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ tmp Makefile .mm-pid-* .idea +*.sublime-workspace diff --git a/.simplecov b/.simplecov deleted file mode 100644 index 56e0129c..00000000 --- a/.simplecov +++ /dev/null @@ -1,6 +0,0 @@ -SimpleCov.start do - add_filter '/features/' - add_filter '/spec/' - add_filter '/vendor' - add_filter '/step_definitions/' -end diff --git a/middleman-core/features/data.feature b/middleman-core/features/data.feature index 7f7e36f7..fcce8445 100644 --- a/middleman-core/features/data.feature +++ b/middleman-core/features/data.feature @@ -5,11 +5,35 @@ Feature: Local Data API Given the Server is running at "basic-data-app" When I go to "/data.html" Then I should see "One:Two" + When the file "data/test.yml" has the contents + """ + - + title: "Three" + - + title: "Four" + """ + When I go to "/data.html" + Then I should see "Three:Four" + When the file "data/test.yml" is removed + When I go to "/data.html" + Then I should see "No Test Data" Scenario: Rendering json Given the Server is running at "basic-data-app" When I go to "/data3.html" Then I should see "One:Two" + When the file "data/test2.json" has the contents + """ + [ + { "title": "Three" }, + { "title": "Four" } + ] + """ + When I go to "/data3.html" + Then I should see "Three:Four" + When the file "data/test2.json" is removed + When I go to "/data3.html" + Then I should see "No Test Data" Scenario: Using data in config.rb Given the Server is running at "data-app" @@ -26,4 +50,4 @@ Feature: Local Data API When I go to "/test.html" Then I should see "title1:Hello" Then I should see "title2:More" - Then I should see "title3:Stuff" \ No newline at end of file + Then I should see "title3:Stuff" diff --git a/middleman-core/fixtures/basic-data-app/source/data.html.erb b/middleman-core/fixtures/basic-data-app/source/data.html.erb index a18f3afc..4322ae7f 100644 --- a/middleman-core/fixtures/basic-data-app/source/data.html.erb +++ b/middleman-core/fixtures/basic-data-app/source/data.html.erb @@ -1 +1,5 @@ -<%= data.test.map { |r| r.title }.join(":") %> \ No newline at end of file +<% if data.respond_to?(:test) %> + <%= data.test.map { |r| r.title }.join(":") %> +<% else %> + No Test Data +<% end %> \ No newline at end of file diff --git a/middleman-core/fixtures/basic-data-app/source/data3.html.erb b/middleman-core/fixtures/basic-data-app/source/data3.html.erb index d2ac7634..32ecc9cc 100644 --- a/middleman-core/fixtures/basic-data-app/source/data3.html.erb +++ b/middleman-core/fixtures/basic-data-app/source/data3.html.erb @@ -1 +1,5 @@ -<%= data.test2.map { |r| r.title }.join(":") %> \ No newline at end of file +<% if data.respond_to?(:test2) %> + <%= data.test2.map { |r| r.title }.join(":") %> +<% else %> + No Test Data +<% end %> \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index a966e3f3..ced1abd8 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -170,7 +170,7 @@ module Middleman # @private # @return [Middleman::Util::Cache] The cache def self.cache - @_cache ||= ::Middleman::Util::Cache.new + @_cache ||= ::Tilt::Cache.new end delegate :cache, :to => :"self.class" diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index ba5e72d5..01ed0c4c 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -146,62 +146,5 @@ module Middleman end end.flatten.compact end - - # Simple shared cache implementation - class Cache - # Initialize - def initialize - self.clear - end - - # Either get the cached key or save the contents of the block - # - # @param key Anything Hash can use as a key - def fetch(*key) - @cache[key] ||= yield - end - - # Whether the key is in the cache - # - # @param key Anything Hash can use as a key - # @return [Boolean] - def has_key?(key) - @cache.has_key?(key) - end - - # Get a specific key - # - # @param key Anything Hash can use as a key - def get(key) - @cache[key] - end - - # Array of keys - # @return [Array] - def keys - @cache.keys - end - - # Clear the entire cache - # @return [void] - def clear - @cache = {} - end - - # Set a specific key - # - # @param key Anything Hash can use as a key - # @param value Cached value - # @return [void] - def set(key, value) - @cache[key] = value - end - - # Remove a specific key - # @param key Anything Hash can use as a key - def remove(*key) - @cache.delete(key) - end - end end end diff --git a/middleman.sublime-project b/middleman.sublime-project new file mode 100644 index 00000000..c4df5142 --- /dev/null +++ b/middleman.sublime-project @@ -0,0 +1,16 @@ +{ + "folders": + [ + { + "path": ".", + "folder_exclude_patterns": [".sass-cache", ".bundle", "tmp", "coverage"], + "file_exclude_patterns": ["*.sublime-workspace"] + } + ], + + "settings": + { + "tab_size": 2, + "translate_tabs_to_spaces": true + } +}