# -*- ruby -*- # vim: set nosta noet ts=4 sw=4: # encoding: utf-8 BEGIN { require 'pathname' basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir ) } require 'pathname' require 'tmpdir' require 'tempfile' require 'stringio' require 'rspec' require 'spec/lib/helpers' require 'strelka/cms' require 'strelka/cms/page' ##################################################################### ### C O N T E X T S ##################################################################### describe Strelka::CMS::Page do TEST_DOCUMENT = (<<-END_TEST_DOCUMENT).gsub( /^\t/, '' ) --- title: Fun With TextMate 2 template: blogentry.tmpl date: 2011-12-16 19:28:45 -0700 tags: - editors - software - tools - textmate2 filters: - example - strip - textile --- I've been playing around with TextMate 2 for a few days, trying to figure out the mountain of changes that have been made, and so far I'm pretty happy with it. Especially considering that it's only an alpha, I'm getting a surprising amount of Real Work™ done with it. One of the things that kept me from switching to a new and shinier editor has been my Ruby workflow, which makes extensive use of the RSpec bundle. I wrote a little formatter for it that can include logging with each spec that you can toggle on and off, and I find it to be a little more compact and readable than the default TextMate formatter. Anyway, I just got the @.tm_properties@ tweaks figured out that are necessary to make RSpec work in the new version: !../images/tm2-webkit-rspec.png! If you're using the WebKit formatter, or any other formatter for that matter, add this to the @.tm_properties@ either in your $HOME (to apply it to all RSpec bundle output), or in a specific project's @.tm_properties@ file: TM_RSPEC_OPTS = '-rrspec/core/formatters/webkit' TM_RSPEC_FORMATTER = 'RSpec::Core::Formatters::WebKit' I'm excited about the possibilities of tweaking the editor's behavior on a directory-by-directory basis. TM2 still has some rough edges, and some stuff that's missing or doesn't work right, but I'm no longer worried that I'll be disappointed by the final 2.0 release. Now, hopefully Alan won't get too frustrated with all the bikeshedders and people that won't read instructions. END_TEST_DOCUMENT before( :all ) do setup_logging() end after( :all ) do reset_logging() end it "can load a page from from disk" do tmp = Tempfile.new( 'test.page' ) tmp.write( TEST_DOCUMENT ) tmp.close page = described_class.load( tmp.path ) page.title.should == 'Fun With TextMate 2' page.tags.should include( 'editors', 'software', 'tools', 'textmate2' ) page.content.should include( 'One of the things that kept me from switching' ) page.path.to_s.should == tmp.path end it "can read a page from an IO stream" do io = StringIO.new( TEST_DOCUMENT, 'r' ) page = described_class.read( io ) page.title.should == 'Fun With TextMate 2' page.tags.should include( 'editors', 'software', 'tools', 'textmate2' ) page.content.should include( 'One of the things that kept me from switching' ) end it "can parse a page from source" do page = described_class.parse( TEST_DOCUMENT ) page.title.should == 'Fun With TextMate 2' page.tags.should include( 'editors', 'software', 'tools', 'textmate2' ) page.content.should include( 'One of the things that kept me from switching' ) end describe "loaded via some means" do let( :page ) { described_class.parse(TEST_DOCUMENT) } it "can generate a summary of its contents" do page.summary.should =~ /^If you're using the WebKit formatter,/ end it "can generate a list of topics from its content" do page.summary_topics.should include( "formatter", "rspec" ) end it "can generate keywords if none are set by the header" do page.instance_variable_set( :@tags, nil ) page.keywords.should include( 'formatter', 'rspec', 'editor', 'textmate' ) end end context "with no options (empty header)" do let( :content ) { "h1. Title\n\nSome content.\n" } let( :page ) { described_class.new(content) } it "has a default set of filters" do page.filters.should == %w[strip textile] end it "returns its contents after applying filters when stringified" do page.to_s.should == %{
Some content.
} end it "can return its first heading" do page.first_heading.should == 'Title' end end context "with a catalog" do let( :basedir ) { Pathname(Dir.tmpdir) } let( :subdir ) do subdir = basedir + 'sub' subdir.mkpath subdir end let( :pagefile ) do file = Tempfile.new( 'test.page', @subdir ) file.write( TEST_DOCUMENT ) file.close file end let( :catalog ) { Strelka::CMS::PageCatalog.new(basedir) } let( :page ) { described_class.load(pagefile.path, catalog) } let( :relative_pagefile_pathname ) do Pathname( pagefile.path ).relative_path_from( catalog.basedir ) end it "knows what its path relative to its catalog's base is" do page.relative_path.should == relative_pagefile_pathname end end end