How to use run method of Filesystem Package

Best Spinach_ruby code snippet using Filesystem.run

mount_spec.rb

Source:mount_spec.rb Github

copy

Full Screen

...19describe Chef::Provider::Mount do20 before(:each) do21 @node = Chef::Node.new22 @events = Chef::EventDispatch::Dispatcher.new23 @run_context = Chef::RunContext.new(@node, {}, @events)24 25 @new_resource = Chef::Resource::Mount.new('/tmp/foo')26 @new_resource.device "/dev/sdz1"27 @new_resource.name "/tmp/foo"28 @new_resource.mount_point "/tmp/foo"29 @new_resource.fstype "ext3"30 31 @current_resource = Chef::Resource::Mount.new('/tmp/foo')32 @current_resource.device "/dev/sdz1"33 @current_resource.name "/tmp/foo"34 @current_resource.mount_point "/tmp/foo"35 @current_resource.fstype "ext3"36 @provider = Chef::Provider::Mount.new(@new_resource, @run_context)37 @provider.current_resource = @current_resource38 end39 40 describe "when the target state is a mounted filesystem" do41 it "should mount the filesystem if it isn't mounted" do42 @current_resource.stub!(:mounted).and_return(false)43 @provider.should_receive(:mount_fs).with.and_return(true)44 @provider.run_action(:mount)45 @new_resource.should be_updated_by_last_action46 end47 it "should not mount the filesystem if it is mounted" do48 @current_resource.stub!(:mounted).and_return(true)49 @provider.should_not_receive(:mount_fs)50 @provider.run_action(:mount)51 @new_resource.should_not be_updated_by_last_action52 end53 end54 describe "when the target state is an unmounted filesystem" do55 it "should umount the filesystem if it is mounted" do56 @current_resource.stub!(:mounted).and_return(true)57 @provider.should_receive(:umount_fs).with.and_return(true)58 @provider.run_action(:umount)59 @new_resource.should be_updated_by_last_action60 end61 it "should not umount the filesystem if it is not mounted" do62 @current_resource.stub!(:mounted).and_return(false)63 @provider.should_not_receive(:umount_fs)64 @provider.run_action(:umount)65 @new_resource.should_not be_updated_by_last_action66 end67 end68 describe "when the filesystem should be remounted and the resource supports remounting" do69 before do70 @new_resource.supports[:remount] = true71 end72 73 it "should remount the filesystem if it is mounted" do74 @current_resource.stub!(:mounted).and_return(true)75 @provider.should_receive(:remount_fs).and_return(true)76 @provider.run_action(:remount)77 @new_resource.should be_updated_by_last_action78 end79 it "should not remount the filesystem if it is not mounted" do80 @current_resource.stub!(:mounted).and_return(false)81 @provider.should_not_receive(:remount_fs)82 @provider.run_action(:remount)83 @new_resource.should_not be_updated_by_last_action84 end85 end86 describe "when the filesystem should be remounted and the resource does not support remounting" do 87 before do 88 @new_resource.supports[:remount] = false89 end90 it "should fail to remount the filesystem" do91 @provider.should_not_receive(:remount_fs)92 lambda {@provider.run_action(:remount)}.should raise_error(Chef::Exceptions::UnsupportedAction)93 @new_resource.should_not be_updated_by_last_action94 end95 end96 describe "when enabling the filesystem to be mounted" do97 it "should enable the mount if it isn't enable" do98 @current_resource.stub!(:enabled).and_return(false)99 @provider.should_not_receive(:mount_options_unchanged?)100 @provider.should_receive(:enable_fs).and_return(true)101 @provider.run_action(:enable)102 @new_resource.should be_updated_by_last_action103 end104 it "should enable the mount if it is enabled and mount options have changed" do105 @current_resource.stub!(:enabled).and_return(true)106 @provider.should_receive(:mount_options_unchanged?).and_return(false)107 @provider.should_receive(:enable_fs).and_return(true)108 @provider.run_action(:enable)109 @new_resource.should be_updated_by_last_action110 end111 it "should not enable the mount if it is enabled and mount options have not changed" do112 @current_resource.stub!(:enabled).and_return(true)113 @provider.should_receive(:mount_options_unchanged?).and_return(true)114 @provider.should_not_receive(:enable_fs).and_return(true)115 @provider.run_action(:enable)116 @new_resource.should_not be_updated_by_last_action117 end118 end119 describe "when the target state is to disable the mount" do120 it "should disable the mount if it is enabled" do121 @current_resource.stub!(:enabled).and_return(true)122 @provider.should_receive(:disable_fs).with.and_return(true)123 @provider.run_action(:disable)124 @new_resource.should be_updated_by_last_action125 end126 it "should not disable the mount if it isn't enabled" do127 @current_resource.stub!(:enabled).and_return(false)128 @provider.should_not_receive(:disable_fs)129 @provider.run_action(:disable)130 @new_resource.should_not be_updated_by_last_action131 end132 end133 it "should delegates the mount implementation to subclasses" do134 lambda { @provider.mount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)135 end136 it "should delegates the umount implementation to subclasses" do137 lambda { @provider.umount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)138 end139 it "should delegates the remount implementation to subclasses" do140 lambda { @provider.remount_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)141 end142 it "should delegates the enable implementation to subclasses" do143 lambda { @provider.enable_fs }.should raise_error(Chef::Exceptions::UnsupportedAction)...

Full Screen

Full Screen

compiler_test.rb

Source:compiler_test.rb Github

copy

Full Screen

1#!/usr/bin/env ruby2require 'minitest/autorun'3require File.dirname(__FILE__) + '/../test_helper'4require 'sass/plugin'5require 'sass/plugin/compiler'6class CompilerTest < MiniTest::Test7 class FakeListener8 attr_accessor :options9 attr_accessor :directories10 attr_reader :start_called11 attr_reader :thread12 def initialize(*args, &on_filesystem_event)13 self.options = args.last.is_a?(Hash) ? args.pop : {}14 self.directories = args15 @on_filesystem_event = on_filesystem_event16 @start_called = false17 reset_events!18 end19 def fire_events!(*args)20 @on_filesystem_event.call(@modified, @added, @removed)21 reset_events!22 end23 def changed(filename)24 @modified << File.expand_path(filename)25 end26 def added(filename)27 @added << File.expand_path(filename)28 end29 def removed(filename)30 @removed << File.expand_path(filename)31 end32 def on_start!(&run_during_start)33 @run_during_start = run_during_start34 end35 # used for Listen < 2.036 def start!37 @run_during_start.call(self) if @run_during_start38 end39 # used for Listen >= 2.040 def start41 parent = Thread.current42 @thread = Thread.new do43 @run_during_start.call(self) if @run_during_start44 parent.raise Interrupt45 end46 end47 def stop48 end49 def reset_events!50 @modified = []51 @added = []52 @removed = []53 end54 end55 module MockWatcher56 attr_accessor :run_during_start57 attr_accessor :update_stylesheets_times58 attr_accessor :update_stylesheets_called_with59 attr_accessor :deleted_css_files60 def fake_listener61 @fake_listener62 end63 def update_stylesheets(individual_files)64 @update_stylesheets_times ||= 065 @update_stylesheets_times += 166 (@update_stylesheets_called_with ||= []) << individual_files67 end68 def try_delete_css(css_filename)69 (@deleted_css_files ||= []) << css_filename70 end71 private72 def create_listener(*args, &on_filesystem_event)73 if Sass::Util.listen_geq_2?74 args.pop if args.last.is_a?(Hash)75 args.map do |dir|76 @fake_listener = FakeListener.new(*args, &on_filesystem_event)77 @fake_listener.on_start!(&run_during_start)78 @fake_listener79 end80 else81 @fake_listener = FakeListener.new(*args, &on_filesystem_event)82 @fake_listener.on_start!(&run_during_start)83 @fake_listener84 end85 end86 end87 def test_initialize88 watcher89 end90 def test_watch_starts_the_listener91 start_called = false92 c = watcher do |listener|93 start_called = true94 end95 c.watch96 assert start_called, "start! was not called"97 end98 def test_sass_callbacks_fire_from_listener_events99 c = watcher do |listener|100 listener.changed "changed.scss"101 listener.added "added.scss"102 listener.removed "removed.scss"103 listener.fire_events!104 end105 modified_fired = false106 c.on_template_modified do |sass_file|107 modified_fired = true108 assert_equal "changed.scss", sass_file109 end110 added_fired = false111 c.on_template_created do |sass_file|112 added_fired = true113 assert_equal "added.scss", sass_file114 end115 removed_fired = false116 c.on_template_deleted do |sass_file|117 removed_fired = true118 assert_equal "removed.scss", sass_file119 end120 c.watch121 assert_equal 2, c.update_stylesheets_times122 assert modified_fired123 assert added_fired124 assert removed_fired125 end126 def test_removing_a_sass_file_removes_corresponding_css_file127 c = watcher do |listener|128 listener.removed "remove_me.scss"129 listener.fire_events!130 end131 c.watch132 assert_equal "./remove_me.css", c.deleted_css_files.first133 end134 def test_an_importer_can_watch_an_image135 image_importer = Sass::Importers::Filesystem.new(".")136 class << image_importer137 def watched_file?(filename)138 filename =~ /\.png$/139 end140 end141 c = watcher(:load_paths => [image_importer]) do |listener|142 listener.changed "image.png"143 listener.fire_events!144 end145 modified_fired = false146 c.on_template_modified do |f|147 modified_fired = true148 assert_equal "image.png", f149 end150 c.watch151 assert_equal 2, c.update_stylesheets_times152 assert modified_fired153 end154 def test_watching_specific_files_and_one_is_deleted155 directories = nil156 c = watcher do |listener|157 directories = listener.directories158 listener.removed File.expand_path("./foo.scss")159 listener.fire_events!160 end161 c.watch([[File.expand_path("./foo.scss"), File.expand_path("./foo.css"), nil]])162 assert directories.include?(File.expand_path(".")), directories.inspect163 assert_equal File.expand_path("./foo.css"), c.deleted_css_files.first, "the corresponding css file was not deleted"164 assert_equal [], c.update_stylesheets_called_with[1], "the sass file should not have been compiled"165 end166 def test_watched_directories_are_dedupped167 directories = nil168 c = watcher(:load_paths => [".", "./foo", "."]) do |listener|169 directories = listener.directories170 end171 c.watch172 assert_equal [File.expand_path(".")], directories173 end174 def test_a_changed_css_in_a_watched_directory_does_not_force_a_compile175 c = watcher do |listener|176 listener.changed "foo.css"177 listener.fire_events!178 end179 c.on_template_modified do |f|180 assert false, "Should not have been called"181 end182 c.watch183 assert_equal 1, c.update_stylesheets_times184 end185 private186 def default_options187 {:template_location => [[".","."]]}188 end189 def watcher(options = {}, &run_during_start)190 options = default_options.merge(options)191 watcher = Sass::Plugin::Compiler.new(options)192 watcher.extend(MockWatcher)193 watcher.run_during_start = run_during_start194 watcher195 end196end...

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1FileSystem.run("ls -l")2 def self.run(command)3 system(command)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spinach_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful