Browse Source

Add cli tests for selecting pry as shell

Ben Cox 11 years ago
parent
commit
387e98edb6
1 changed files with 22 additions and 3 deletions
  1. 22 3
      test/cli_test.rb

+ 22 - 3
test/cli_test.rb

@@ -30,7 +30,8 @@ class CliTest < Test::Unit::TestCase
     $stdout.expects(:print).with("Domain? (leave blank for foo.myshopify.com) ")
     $stdout.expects(:print).with("API key? ")
     $stdout.expects(:print).with("Password? ")
-    $stdin.expects(:gets).times(3).returns("", "key", "pass")
+    $stdout.expects(:print).with("Would you like to use pry as your shell? (y/n)")
+    $stdin.expects(:gets).times(4).returns("", "key", "pass", "y")
     @cli.expects(:puts).with("\nopen https://foo.myshopify.com/admin/api in your browser to get API credentials\n")
     @cli.expects(:puts).with("Default connection is foo")
 
@@ -40,6 +41,7 @@ class CliTest < Test::Unit::TestCase
     assert_equal 'foo.myshopify.com', config['domain']
     assert_equal 'key', config['api_key']
     assert_equal 'pass', config['password']
+    assert_equal 'pry', config['shell']
     assert_equal 'https', config['protocol']
     assert_equal config_file('foo'), File.readlink(@default_symlink)
   end
@@ -49,7 +51,8 @@ class CliTest < Test::Unit::TestCase
     $stdout.expects(:print).with("Domain? (leave blank for foo.myshopify.com) ")
     $stdout.expects(:print).with("API key? ")
     $stdout.expects(:print).with("Password? ")
-    $stdin.expects(:gets).times(3).returns("bar.myshopify.com", "key", "pass")
+    $stdout.expects(:print).with("Would you like to use pry as your shell? (y/n)")
+    $stdin.expects(:gets).times(4).returns("bar.myshopify.com", "key", "pass", "y")
     @cli.expects(:puts).with("\nopen https://bar.myshopify.com/admin/api in your browser to get API credentials\n")
     @cli.expects(:puts).with("Default connection is foo")
 
@@ -59,6 +62,22 @@ class CliTest < Test::Unit::TestCase
     assert_equal 'bar.myshopify.com', config['domain']
   end
 
+  test "add with irb as shell" do
+    `rm -rf #{@shop_config_dir}/*`
+    $stdout.expects(:print).with("Domain? (leave blank for foo.myshopify.com) ")
+    $stdout.expects(:print).with("API key? ")
+    $stdout.expects(:print).with("Password? ")
+    $stdout.expects(:print).with("Would you like to use pry as your shell? (y/n)")
+    $stdin.expects(:gets).times(4).returns("bar.myshopify.com", "key", "pass", "fuuuuuuu")
+    @cli.expects(:puts).with("\nopen https://bar.myshopify.com/admin/api in your browser to get API credentials\n")
+    @cli.expects(:puts).with("Default connection is foo")
+
+    @cli.add('foo')
+
+    config = YAML.load(File.read(config_file('foo')))
+    assert_equal 'irb', config['shell']
+  end
+
   test "list" do
     @cli.expects(:puts).with("   bar")
     @cli.expects(:puts).with(" * foo")
@@ -99,7 +118,7 @@ class CliTest < Test::Unit::TestCase
   private
 
   def valid_options
-    {'domain' => 'snowdevil.myshopify.com', 'api_key' => 'key', 'password' => 'pass', 'protocol' => 'https'}
+    {'domain' => 'snowdevil.myshopify.com', 'api_key' => 'key', 'password' => 'pass', 'shell' => 'pry', 'protocol' => 'https'}
   end
 
   def config_file(connection)