gotime-slither 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Slither do
4
+
5
+ before(:each) do
6
+ @name = :doc
7
+ @options = { :align => :left }
8
+ end
9
+
10
+ describe "when defining a format" do
11
+ before(:each) do
12
+ @definition = mock('definition')
13
+ end
14
+
15
+ it "should create a new definition using the specified name and options" do
16
+ Slither.should_receive(:define).with(@name, @options).and_return(@definition)
17
+ Slither.define(@name , @options)
18
+ end
19
+
20
+ it "should pass the definition to the block" do
21
+ yielded = nil
22
+ Slither.define(@name) do |y|
23
+ yielded = y
24
+ end
25
+ yielded.should be_a( Slither::Definition )
26
+ end
27
+
28
+ it "should add to the internal definition count" do
29
+ Slither.definitions.clear
30
+ Slither.should have(0).definitions
31
+ Slither.define(@name , @options) {}
32
+ Slither.should have(1).definitions
33
+ end
34
+ end
35
+
36
+ describe "when creating file from data" do
37
+ it "should raise an error if the definition name is not found" do
38
+ lambda { Slither.generate(:not_there, {}) }.should raise_error(ArgumentError)
39
+ end
40
+
41
+ it "should output a string" do
42
+ definition = mock('definition')
43
+ generator = mock('generator')
44
+ generator.should_receive(:generate).with({})
45
+ Slither.should_receive(:definition).with(:test).and_return(definition)
46
+ Slither::Generator.should_receive(:new).with(definition).and_return(generator)
47
+ Slither.generate(:test, {})
48
+ end
49
+
50
+ it "should output a file" do
51
+ file = mock('file')
52
+ text = mock('string')
53
+ file.should_receive(:write).with(text)
54
+ File.should_receive(:open).with('file.txt', 'w').and_yield(file)
55
+ Slither.should_receive(:generate).with(:test, {}).and_return(text)
56
+ Slither.write('file.txt', :test, {})
57
+ end
58
+ end
59
+
60
+ describe "when parsing a file" do
61
+ before(:each) do
62
+ @file_name = 'file.txt'
63
+ end
64
+
65
+ it "should check the file exists" do
66
+ lambda { Slither.parse(@file_name, :test, {}) }.should raise_error(ArgumentError)
67
+ end
68
+
69
+ it "should raise an error if the definition name is not found" do
70
+ Slither.definitions.clear
71
+ File.stub!(:exists? => true)
72
+ lambda { Slither.parse(@file_name, :test, {}) }.should raise_error(ArgumentError)
73
+ end
74
+
75
+ it "should create a parser and call parse" do
76
+ File.stub!(:exists? => true)
77
+ file_io = mock("IO")
78
+ parser = mock("parser")
79
+ definition = Slither::Definition.new :by_bytes => false
80
+
81
+ File.should_receive(:open).and_return(file_io)
82
+ Slither.should_receive(:definition).with(:test).and_return(definition)
83
+ Slither::Parser.should_receive(:new).with(definition, file_io).and_return(parser)
84
+ parser.should_receive(:parse).and_return("parse result")
85
+
86
+ Slither.parse(@file_name, :test).should eq("parse result")
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'gotime-slither.rb'))
3
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gotime-slither
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Wood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bones
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.5.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.5.1
27
+ description: A simple, clean DSL for describing, writing, and parsing fixed-width
28
+ text files.
29
+ email: ryan.wood@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - README.rdoc
35
+ files:
36
+ - History.txt
37
+ - README.rdoc
38
+ - Rakefile
39
+ - TODO
40
+ - gotime-slither.gemspec
41
+ - lib/gotime-slither.rb
42
+ - lib/slither/column.rb
43
+ - lib/slither/definition.rb
44
+ - lib/slither/generator.rb
45
+ - lib/slither/parser.rb
46
+ - lib/slither/section.rb
47
+ - lib/slither/slither.rb
48
+ - spec/column_spec.rb
49
+ - spec/definition_spec.rb
50
+ - spec/generator_spec.rb
51
+ - spec/parser_spec.rb
52
+ - spec/section_spec.rb
53
+ - spec/slither_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: http://github.com/ryanwood/slither
56
+ licenses: []
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options:
60
+ - "--main"
61
+ - README.rdoc
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: !binary |-
76
+ AA==
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 2
80
+ summary: A simple, clean DSL for describing, writing, and parsing fixed-width text
81
+ files
82
+ test_files: []