write some file change and deletion tests for better data coverage

This commit is contained in:
Thomas Reynolds 2013-05-29 10:59:03 -04:00
parent b8b48afcbb
commit 86cd626084
8 changed files with 53 additions and 67 deletions

1
.gitignore vendored
View file

@ -17,3 +17,4 @@ tmp
Makefile Makefile
.mm-pid-* .mm-pid-*
.idea .idea
*.sublime-workspace

View file

@ -1,6 +0,0 @@
SimpleCov.start do
add_filter '/features/'
add_filter '/spec/'
add_filter '/vendor'
add_filter '/step_definitions/'
end

View file

@ -5,11 +5,35 @@ Feature: Local Data API
Given the Server is running at "basic-data-app" Given the Server is running at "basic-data-app"
When I go to "/data.html" When I go to "/data.html"
Then I should see "One:Two" 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 Scenario: Rendering json
Given the Server is running at "basic-data-app" Given the Server is running at "basic-data-app"
When I go to "/data3.html" When I go to "/data3.html"
Then I should see "One:Two" 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 Scenario: Using data in config.rb
Given the Server is running at "data-app" Given the Server is running at "data-app"
@ -26,4 +50,4 @@ Feature: Local Data API
When I go to "/test.html" When I go to "/test.html"
Then I should see "title1:Hello" Then I should see "title1:Hello"
Then I should see "title2:More" Then I should see "title2:More"
Then I should see "title3:Stuff" Then I should see "title3:Stuff"

View file

@ -1 +1,5 @@
<%= data.test.map { |r| r.title }.join(":") %> <% if data.respond_to?(:test) %>
<%= data.test.map { |r| r.title }.join(":") %>
<% else %>
No Test Data
<% end %>

View file

@ -1 +1,5 @@
<%= data.test2.map { |r| r.title }.join(":") %> <% if data.respond_to?(:test2) %>
<%= data.test2.map { |r| r.title }.join(":") %>
<% else %>
No Test Data
<% end %>

View file

@ -170,7 +170,7 @@ module Middleman
# @private # @private
# @return [Middleman::Util::Cache] The cache # @return [Middleman::Util::Cache] The cache
def self.cache def self.cache
@_cache ||= ::Middleman::Util::Cache.new @_cache ||= ::Tilt::Cache.new
end end
delegate :cache, :to => :"self.class" delegate :cache, :to => :"self.class"

View file

@ -146,62 +146,5 @@ module Middleman
end end
end.flatten.compact end.flatten.compact
end 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
end end

16
middleman.sublime-project Normal file
View file

@ -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
}
}