ataru 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcbdef8608fe4c9f4b1980f83af3aef1fd23bcd6
4
- data.tar.gz: 1a6d8144749525a5a9b7b5b6eaa2b8415c7d7aca
3
+ metadata.gz: 275aed877820525a59f2c7ad8843ca1cf75deec6
4
+ data.tar.gz: b26d4c1513cc9448578df33c5ba326865c22f58a
5
5
  SHA512:
6
- metadata.gz: 21e1251423908020c79a09eec665fb495c7f5549f315bcd0ad4978475fd135c586b80ebaa71a1d66533de918cd991ce22c2b4b92c531ec547d826a30719ceef9
7
- data.tar.gz: 922a4de8be0b190c4095dd3ad1eeec4407f4d6bd33a73b90af6f8f8795cfd9be066b646a06f7a332fd710412fb47ded005393a27660aa0d492457d37f2dbb2af
6
+ metadata.gz: e8112d22c879ec32f86ed22370097e5c4988a60ef7b98cbf9c439d4967bc7d1d83e465ba658154a5b9d44a1c7e4c47cec7588f34dee6de70f6036f6e138508f2
7
+ data.tar.gz: d3b74b70233e7c708a35421998b829e9553772e5df083d4c162cffbb91437a8e2f47975ca3226357302c3682b90e1c87f7d72c9bfe16b0a1822eb2913d3f7315
data/README.md CHANGED
@@ -16,16 +16,17 @@ The output of the results has the MiniTest style.
16
16
  - Ataru can read files written in Github Flavoured Markdown, as it uses Kramdown with Github Flavoured Markdown Parser.
17
17
 
18
18
  - Ataru is currently able to test the Ruby code only.
19
+ It checks the Ruby syntax and implements assertions (`assert_equal`) in place of `#=>` and `# =>`.
19
20
 
20
21
  ## Requirements
21
22
 
22
23
  - The dependencies of your gem have to be in the range of the latest major versions of:
23
24
 
24
- - minitest (~> 5)
25
- - kramdown (~> 1)
26
- - thor (~> 0)
25
+ - minitest (~> 5.0)
26
+ - kramdown (~> 1.3)
27
+ - thor (~> 0.19.0)
27
28
 
28
- - You need to create the setup file (for more info read Setup section).
29
+ - In most cases, you need to create the setup file (for more info read Setup section).
29
30
 
30
31
  ## Usage as command line tool
31
32
 
@@ -55,6 +56,61 @@ The output of the results has the MiniTest style.
55
56
  ```
56
57
  5. Check the results.
57
58
 
59
+ ## Example
60
+
61
+ If this is a file called `example.md`:
62
+
63
+ ```ruby
64
+ def bad
65
+ false
66
+ end
67
+
68
+ def good
69
+ true
70
+ end
71
+
72
+ bad #=> true
73
+ good #=> true
74
+ ```
75
+
76
+
77
+ which renders as:
78
+
79
+ ```ruby
80
+ def bad
81
+ false
82
+ end
83
+
84
+ def good
85
+ true
86
+ end
87
+
88
+ bad #=> true
89
+ good #=> true
90
+ ```
91
+
92
+ Check it with ataru:
93
+
94
+ ```sh
95
+ $ ataru check example.md
96
+ Run options: --seed 33946
97
+
98
+ # Running:
99
+
100
+ F
101
+
102
+ Finished in 0.001232s, 811.9236 runs/s, 811.9236 assertions/s.
103
+
104
+ 1) Failure:
105
+ #<Class:0x000000033451b8>#test_example_0 [example.md:10]:
106
+ Expected: true
107
+ Actual: false
108
+
109
+ 1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
110
+ ```
111
+
112
+
113
+
58
114
  ## Workflow with Travis CI
59
115
 
60
116
  1. Add ataru to your project Gemfile.
@@ -71,7 +127,7 @@ The output of the results has the MiniTest style.
71
127
  $ bundle exec ataru setup
72
128
  ```
73
129
 
74
- 4. In your .travis.yml file add:
130
+ 4. In your `.travis.yml` file add:
75
131
  - in case you want to check all the markdown files from your project:
76
132
 
77
133
  ```
@@ -92,8 +148,43 @@ The output of the results has the MiniTest style.
92
148
  ## Setup
93
149
 
94
150
  The setup file has to be created in order to enable ataru to read your project source code and use it for its checks.
95
- Ataru comes with an easy to use generator for creating that file. When the generator process is finished, the created
96
- setup file is automatically passed to ataru.
151
+ What is more, in that file you can write some setup code, that will be run before (and after, shall you want that) each snippet.
152
+ If you'd like to use instance variables, define them in `setup` method.
153
+ If you'd like to clean up after running tests, write your clean up code in `teardown` method.
154
+ If you like local variables, you can use methods (see example below).
155
+
156
+ #### Example
157
+
158
+ This is `ataru_setup.rb` file for an imaginary gem `my_fancy_lib`, where instance and local variables `@number` and `number` are defined:
159
+
160
+ ```ruby
161
+ require 'my_fancy_lib'
162
+
163
+ module Setup
164
+ def setup
165
+ @number = 21
166
+ end
167
+
168
+ def teardown
169
+ end
170
+
171
+ def number
172
+ 12
173
+ end
174
+ ```
175
+
176
+ which allows us to use them in the code snippets in `README.md` file:
177
+
178
+ ```ruby
179
+ assert_equal @number + 1, 22
180
+ ```
181
+
182
+ ```ruby
183
+ assert_equal number + 1, 13
184
+ ```
185
+
186
+ Ataru comes with an easy to use generator for creating the setup file. When the generator process is finished, created
187
+ file is automatically passed to ataru.
97
188
 
98
189
  To create the setup file execute:
99
190
 
@@ -101,13 +192,8 @@ To create the setup file execute:
101
192
  $ bundle exec ataru setup
102
193
  ```
103
194
 
104
- Open created file in your text editor and write:
105
-
106
- ```
107
- require "your_project_name"
108
- ```
109
-
110
- Save the file.
195
+ Open created file in your text editor, do your requires and, optionally, write some setup code.
196
+ Save the file.
111
197
 
112
198
  ## Contributing
113
199
 
@@ -5,7 +5,7 @@ require 'ataru/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "ataru"
8
- spec.version = "0.1.0"
8
+ spec.version = "0.2.0"
9
9
  spec.authors = ["Code_Padawans"]
10
10
  spec.email = ["hello@code-padawans.de"]
11
11
  spec.summary = %q{A documentation testing tool}
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake", "~> 10.3"
23
23
 
24
- spec.add_runtime_dependency "minitest", "~> 5"
25
- spec.add_runtime_dependency "kramdown", "~> 1"
26
- spec.add_runtime_dependency "thor", "~> 0"
24
+ spec.add_runtime_dependency "minitest", "~> 5.0"
25
+ spec.add_runtime_dependency "kramdown", "~> 1.3"
26
+ spec.add_runtime_dependency "thor", "~> 0.19.0"
27
27
  end
@@ -0,0 +1,12 @@
1
+ ```ruby
2
+ def bad
3
+ false
4
+ end
5
+
6
+ def good
7
+ true
8
+ end
9
+
10
+ bad #=> true
11
+ good #=> true
12
+ ```
@@ -12,20 +12,36 @@ module Ataru
12
12
 
13
13
  desc "setup", "Create the setup file containing all dependencies for running code snippets"
14
14
  def setup
15
- create_file(Dir.pwd + "/ataru_setup.rb") do
16
- <<-eos
17
- # "Please require your project source code, with the correct path"
15
+ create_file(File.join(Dir.pwd, "ataru_setup.rb"), <<-EOS)
16
+ # "Require your project source code, with the correct path"
18
17
 
19
- # require "path_to_your_project_source_code"
20
- eos
21
- end
18
+ # require 'my_fancy_lib'
19
+
20
+ module Setup
21
+ def setup
22
+ # Do some nice setup that is run before every snippet
23
+ # If you'd like to use instance variables define them here, e.g
24
+ # @important_variable_i_will_use_in_my_code_snippets = true
25
+ end
26
+
27
+ def teardown
28
+ # Do some cleanup that is run after every snippet
29
+ end
30
+
31
+ # If you like local variables you can define methods, e.g
32
+ # def number_of_wishes
33
+ # 101
34
+ # end
35
+
36
+ end
37
+ EOS
22
38
  puts "Well done, young Padawan!\nNow, change the created ataru_setup.rb file."
23
39
  end
24
40
 
25
41
  desc "check", "Check code snippets in all .md files of the project or, if given, specific .md files"
26
42
  def check(*filenames)
27
43
  if filenames.length == 0
28
- filenames = Dir.glob('**/*md')
44
+ filenames = Dir.glob('**/*md') - Dir.glob("vendor/**/*.md")
29
45
  end
30
46
  path = Dir.pwd + '/ataru_setup.rb'
31
47
  require path if File.exist?(path)
@@ -1,6 +1,5 @@
1
1
  require 'minitest'
2
2
  require 'pathname'
3
- require_relative 'errors'
4
3
  require_relative 'code_sample'
5
4
 
6
5
  module Ataru
@@ -14,17 +13,12 @@ module Ataru
14
13
  def build_test_class
15
14
  samples = code_samples
16
15
  klass = Class.new(MiniTest::Test) do
16
+ path = Dir.pwd + '/ataru_setup.rb'
17
+ include Setup if File.exist?(path)
17
18
  samples.each_with_index do |sample, index|
18
19
  basename = Pathname.new(sample.file).basename(".*").to_s
19
20
  define_method("test_#{basename}_#{index}") do
20
-
21
- b = binding
22
-
23
- begin
24
- sample.run(b)
25
- rescue StandardError => e
26
- raise AtaruError.new("In the file: #{sample.file}, in line: #{sample.line_number}, the code sample number: #{index} is raising an error:" + e.inspect)
27
- end
21
+ sample.run(binding)
28
22
  end
29
23
  end
30
24
  end
@@ -19,7 +19,7 @@ end
19
19
 
20
20
  a = 10
21
21
  b = add2(a)
22
- assert_equal 11, b
22
+ asert_equal 11, b
23
23
  b #=> 11
24
24
  ```
25
25
 
@@ -1,7 +1,6 @@
1
1
  require 'minitest/autorun'
2
2
  require 'kramdown'
3
3
  require_relative '../lib/ataru/test_class_builder'
4
- require_relative '../lib/ataru/errors'
5
4
  require_relative '../lib/ataru/code_sample'
6
5
 
7
6
  class TestClassBuilderTest < MiniTest::Test
@@ -32,11 +31,13 @@ class TestClassBuilderTest < MiniTest::Test
32
31
 
33
32
  def test_invalid_code_sample
34
33
  code_samples = [CodeSample.new("a + 1", "my_test.md", 5)]
35
- message = AtaruError.new("In the file: #{code_samples[0].file}, in line: #{code_samples[0].line_number}, is raising an error:")
36
34
  klass = TestClassBuilder.new(code_samples).build_test_class
37
-
38
- assert_raises(AtaruError) { klass.new(@name_of_the_runnable).send(:test_my_test_0) }
39
- assert_equal "In the file: my_test.md, in line: 5, is raising an error:", message.to_s
35
+ #rubinius bug https://github.com/rubinius/rubinius/issues/3101
36
+ exception_class = if RUBY_ENGINE == 'rbx'
37
+ NoMethodError
38
+ else
39
+ NameError
40
+ end
41
+ assert_raises(exception_class) { klass.new(@name_of_the_runnable).send(:test_my_test_0) }
40
42
  end
41
-
42
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ataru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code_Padawans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,42 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '5'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '5'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: kramdown
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '1'
61
+ version: '1.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '1'
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.19.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.19.0
83
83
  description: A documentation testing tool, for documentation in Markdown files, for
84
84
  Ruby code
85
85
  email:
@@ -97,12 +97,12 @@ files:
97
97
  - Rakefile
98
98
  - ataru.gemspec
99
99
  - bin/ataru
100
+ - example.md
100
101
  - lib/ataru.rb
101
102
  - lib/ataru/application.rb
102
103
  - lib/ataru/argument_checker.rb
103
104
  - lib/ataru/cli/application.rb
104
105
  - lib/ataru/code_sample.rb
105
- - lib/ataru/errors.rb
106
106
  - lib/ataru/markdown_loader.rb
107
107
  - lib/ataru/test_class_builder.rb
108
108
  - lib/ataru/test_converter.rb
@@ -1,4 +0,0 @@
1
- module Ataru
2
- class AtaruError < StandardError
3
- end
4
- end