butterfly_net 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,8 +1,10 @@
1
1
  butterfly_net
2
2
 
3
- by Chris Smith
3
+ Version: 0.0.2
4
4
 
5
- http://github.com/quartzmo/butterfly_net
5
+ Author: Chris Smith
6
+ Email: quartzmo@gmail.com
7
+ Project homepage: http://github.com/quartzmo/butterfly_net
6
8
 
7
9
  DESCRIPTION
8
10
 
@@ -24,6 +26,25 @@ USAGE
24
26
  bn, bn_open - Open an active test case, with optional string arg file_name ('.rb' is appended if needed)
25
27
  bnc, bn_close - Close the active test case, and write the output to a file
26
28
 
29
+ Ruby on Rails console:
30
+
31
+ For repeatable tests, be sure to load the Rails test environment with "./script/console test".
32
+ In a Rails project, you can run all tests with the standard rake command 'rake test',
33
+ or an individual test by adding the test directory to the path with the option -I when you invoke Ruby.
34
+
35
+ chris$ ./script/console test
36
+ Loading test environment (Rails 2.3.4)
37
+ >> bn "test/unit/person_console_test"
38
+ . . .
39
+ >> Person.count
40
+ => 2
41
+ >> exit
42
+ . . .
43
+ chris$ ruby -Itest test/unit/person_console_test.rb
44
+ . . .
45
+ 1 tests, 1 assertions, 0 failures, 0 errors
46
+
47
+
27
48
  LICENSE
28
49
 
29
50
  (The MIT License)
@@ -10,8 +10,12 @@ module ButterflyNet
10
10
  module Commands
11
11
 
12
12
  def bn_open(file_name=nil)
13
+
14
+
13
15
  @file.close if @file
14
16
  check_for_readline
17
+ # todo: if Rails, WARNING if env is not test
18
+
15
19
  start_index = Readline::HISTORY.empty? ? 0 : (Readline::HISTORY.size - 1)
16
20
  file_name ||= "butterfly_net_#{Time.now.strftime("%Y%m%d%H%M%S")}.rb"
17
21
  file_name += ".rb" unless file_name =~ /.rb$/
@@ -18,16 +18,26 @@ module ButterflyNet
18
18
 
19
19
  def create_file(filename)
20
20
  return nil if @assertion_sets.empty?
21
- file = File.open(filename, 'w+')
22
- file.puts "require \"test/unit\"\n\nclass TempTest < Test::Unit::TestCase"
21
+
22
+ #todo detect existing file, and delete last 'end' line
23
+ file = File.open(filename, 'a+') # starts at end of file if file exists
24
+
25
+ if defined? ActiveSupport::TestCase # rails # todo support earlier versions of rails
26
+ file.puts "require \"test_helper\"\n\nclass TempTest < ActiveSupport::TestCase"
27
+ else
28
+ file.puts "require \"test/unit\"\n\nclass TempTest < Test::Unit::TestCase"
29
+ end
23
30
 
24
31
  test_methods.each do |test_method|
25
32
  file.puts "\n #{test_method}"
26
33
  end
27
34
 
28
- file.puts "\nend"
29
35
  ensure
30
- file.close if file # todo: closing is good, but prevent writing partial data in case of exception
36
+ if file # todo: closing is always good, but prevent writing partial data in case of exception
37
+ file.puts "\nend"
38
+ file.close
39
+ end
40
+
31
41
  end
32
42
 
33
43
  def test_methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: butterfly_net
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Smith
@@ -13,14 +13,7 @@ date: 2010-02-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: |+
17
- IRB history captured as Test::Unit tests. (RSpec and others hopefully soon to come.)
18
-
19
- Command methods:
20
-
21
- bn, bn_open - Open an active test case, with optional string arg file_name ('.rb' is appended if needed)
22
- bnc, bn_close - Close the active test case, and write the output to a file
23
-
16
+ description: IRB and Rails console history captured as Test::Unit tests. (RSpec and others hopefully soon to come.)
24
17
  email: quartzmo@gmail.com
25
18
  executables: []
26
19
 
@@ -65,6 +58,6 @@ rubyforge_project:
65
58
  rubygems_version: 1.3.5
66
59
  signing_key:
67
60
  specification_version: 3
68
- summary: IRB history captured as Test::Unit tests. (RSpec and others hopefully soon to come.)
61
+ summary: IRB and Rails console history captured as Test::Unit tests. (RSpec and others hopefully soon to come.)
69
62
  test_files:
70
63
  - test/butterfly_net_tests.rb